Hi, I’m new in Unity, I’m create a plant growing simulation game on android platform. I’m using texture button as my button to trigger a game objects. I was able to set it into inactive state, but unable to reactive it… The following is part of my code in GUI Texture.
public class FertilizerBTN : MonoBehaviour {
public static int currTouch = 0; //so other scripts can know what touch is currently on screen
// Use this for initialization
public GameObject fer;
void Start () {
fer = GameObject.Find("Fertilizers");
fer.SetActive(false);
}
// Update is called once per frame
void Update () {
if(Input.touches.Length <= 0){
//if no touches then execute this code
}
else //if there is a touch
{
//loop through all the the touches on screen
for(int i = 0; i < Input.touchCount; i++)
{
currTouch = i;
//executes this code for current touch (i) on screen
if(this.guiTexture != null && (this.guiTexture.HitTest(Input.GetTouch(i).position)))
{
//if current touch hits our guitexture, run this code
if(Input.GetTouch(i).phase == TouchPhase.Began)
{
fer = GameObject.Find("Fertilizers");
fer.SetActive(true);
Debug.Log("OnTouchBegan");
}
if(Input.GetTouch(i).phase == TouchPhase.Ended)
{
this.SendMessage("OnTouchEnded");
}
if(Input.GetTouch(i).phase == TouchPhase.Moved)
{
this.SendMessage("OnTouchMoved");
}
}
}
}
}
}
I’m sorry if I’m done some newbie mistakes… Hope to get help soon, please and thank you.