I'm writing a script to change the image on the button based on previous selection.
Another script is giving the CurrentAvatar
variable once previous button is pressed.
My problem is i can't seem to load an image for the button using:
AvatarSprite = Resources.Load<Sprite>("Assets/Images/FireMonsters/Lamor_Icon");
Could someone please enlighten me on the proper code?
All from assets, or is it even possible?
Also looking to have multiple options in if
statements, don't know a better method.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SelectedAvatar : MonoBehaviour {
Button CurrentHeroSprite;
static Sprite AvatarSprite;
public static string CurrentAvatar;
// Use this for initialization
void Start () {
CurrentHeroSprite = GetComponent<Button>();
}
// Update is called once per frame
void Update () {
if (CurrentAvatar == "Lamor") {
AvatarSprite = Resources.Load<Sprite>("Assets/Images/FireMonsters/Lamor_Icon");
CurrentHeroSprite.image.sprite = AvatarSprite;
Debug.Log ("loaded sprite for Lamor");
}
//if etc etc etc
}
}