- Home /
hit moving Gameobject by touch
My game is sphere moving and you should touch it when it is moving I use this script
if (Input.touchCount > 0)
// && Input.GetTouch(0).phase == TouchPhase.Began
{
Debug.Log("Yes");
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
Debug.Log(" You just hit " + hit.collider.gameObject.name);
to hit moving GameObject but if i want to hit it when i play it doesn't work i should hit front of it (sorry about my simple English)
you can use mouse event for one touch..
void On$$anonymous$$ouseDown() { ... }
use this function on the sphere..and this method helps you to do some things, when you touch (in mobile) or click this object..
$$anonymous$$ake sure your sphere has a collider and it is enabled. Also check to make sure there aren't other colliders in the way that might be obstructing the path to the sphere. Does your Debug.Log(" You just hit... ever get called?
$$anonymous$$ake sure your sphere has a collider and it is enabled. Also check to make sure there aren't other colliders in the way that might be obstructing the path to the sphere. Does your Debug.Log(" You just hit... ever get called?
yes every thing is good and my sphere had a Sphere Collider(&Is Trigger) But if i play the Game it's like the collider is more faster than sphere or the touch have a lag.