Hello guys,
I am a new c# learner, and recently I am stuck with my first test script, I hope I can get some help here. Thanks in advance.
This is my script:
using UnityEngine;
using System.Collections;
public class touch2 :MonoBehaviour
{
public GUITexture guitex ;
public Ray ray;
public void Update()
{
for (int i = 0; i < Input.touchCount; i++) {
// turn on guitex
ray = Camera.main.ScreenPointToRay (Input.GetTouch (i).position);
if (Physics.Raycast (ray)) {
guitex.enabled=true;
}
//turn off guitex
if (guitex.HitTest (Input.GetTouch (i).position)) {
guitex.enabled= false;
}
}
}
}
My purpose is apply this to different objects (Cube and Sphere in this case), when I touch the cube, GUItexture1 will show up, and when I touch sphere, GUItexture2 will appear. By touching on the Guitexture they will disappear accordingly.
Now the problem is when I touch either of those objects, both GUItexture is displayed, and I don’t know which part is wrong, but when I tried to use OnMouseDown method instead of ray it just work perfectly.