How can I enable/disable a sprite from a script? Please Help
I'm trying to make a lock sprite appear when something is locked and disappear when it is unlocked.
Comment
Best Answer
Answer by Mmmpies · May 31, 2016 at 05:44 PM
Easiest way is a public variable in the script that you enable.
If using the 4.6 UI just do this.
public Image lockImg;
You also need this;
using UnityEngine.UI;
At the top of the script to use UI elements in the script. Then when you want it enabling...
lockImg.enabled = true;
and false to disable it. Once the script is saved simply drag the Image onto the slot in the inspector.
So
public SpriteRenderer LockSpright;
Then
LockSprite.enabled = false;
Or true to see it.