- Home /
Touching moving sprites
I am making a 2D game where I have to touch two moving sprites. Evertything works but the touch. Both sprites have a rigidbody 2d and a box collider 2D. The problem is that when I touch a sprite nothing happens. Not even the Debug.Log.
Here is my script:
#pragma strict
function Update ()
{
if (Input.touchCount > 0)
{
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
Debug.Log("Touch");
if(hit.collider.tag == "sprite1")
{
Debug.Log("Works");
}
if(hit.collider.tag == "sprite2")
{
Debug.Log("Works2");
}
}
}
}
Not even the Debug.Log outsides the if statement that checks the tag of sprite is working. I have tried the game on both android and ios devices and neither worked.
Comment
Your answer
Follow this Question
Related Questions
How do I create a 2d shooting mechanic (Left and Right)? 1 Answer
How to have coins burst out in random directions after destroying an object in unity? 2 Answers
SNAKE [Tail] 0 Answers
OnColliderEnter2D not working! 3 Answers
Drag and release 2 Answers