- Home /
When I load image it dissapears
I am trying to change image when the score reaches 10. But everytiem when the score reaches 10 the texture of image dissapears. BTW I am making ranks in clicker game. There's the code:
public class Click : MonoBehaviour {
public UnityEngine.UI.Text CSGOMoney;
public UnityEngine.UI.Text MPC;
public float money = 0;
public int moneyperclick = 1;
public Image image;
void Update(){
CSGOMoney.text = "Money-" + money;
MPC.text = "Money per click-" + moneyperclick;
if (money == 10f) {
ChangeImg ();
}
}
public void ChangeImg(){
image.sprite = Resources.Load<Sprite> ("Ranks_3");
}
public void Clicked(){
money += moneyperclick;
}
}
Thanks!
Hello buddy,
No need to use Resources for this.. Just create a Public Sprite variable and fill it in the inspector. Then...
public Sprite Rank3_Sprite;
public void ChangeImg(){
image.sprite = Rank3_Sprite;
}
Answer by LocalNoob · Aug 01, 2017 at 11:01 AM
Check if your image ui elements has its color's alpha at 0 and set it to 255 if so. It often is transparent by default
Answer by Buemi-CZ782 · Aug 10, 2017 at 06:34 PM
@LocalNoob I mean this:
But thanks for your help!
Your answer
Follow this Question
Related Questions
Changing a UI image sprite in scripts results in a black texture 0 Answers
Sprite Becoming Blurry 2 Answers
Unable to drag image from Assets folder to Sprite: None under Sprite Renderer. 0 Answers
Scaling giant images as 2D Sprite 0 Answers
How do i generate random types of sprites in game ?,Can i set a variable to an image asset ? 0 Answers