- Home /
Showing image, when a button is pressed
Hey! I am trying to create a GUI for mana resource. So I try to make an image disappear after a mouse button is pressed. I am not quite sure how to do it properly and I am asking for the advice.
The way I imagine doing it: I attach the script to the character. I parent canvas obejct to the character. I parent the image to the canvas (and manually adjust the position of the picture). Then in the script, I drag and drop my image, after that through scripting I disable and/or enable the image.
I suppose it should look like that, am I right?
using UnityEngine;
using System.Collections;
public class imagescript : MonoBehaviour {
public Sprite mana1;
void Update () {
if (Input.GetButton("Fire1")){
mana1.isEnabled == false;
}
}
}
Thank you!
Darsh2019, it works! Thank you very much!!! Please convert your comment to an answer, so I could upvote it!
your welcome.Let me know if you get any error.vote for the answer..
Answer by Darsh2019 · Feb 16, 2015 at 06:34 AM
if your Image is parent of canvas then there is problem because when you disable it by button press your canvas is also going to disable. So first remove your image as parent. -->after that: public Gameobject mana1; -->on button pressed mana1.setActive(false);
Save your script and drag and drop your image sprite.. hope this help. sry for bad ENGLISH.
Your answer
Follow this Question
Related Questions
Clickable button area is offset 0 Answers
UI Image not blocking raycast 3 Answers
Animation Bug! 0 Answers
how do i make my button's source image bigger without changing the button hover/clickable area? 0 Answers
I want to make responsive homescreen. how to make responsive homescreen UI like this example ? 0 Answers