- Home /
Touch collision detection with a sprite
Hello, I am making a 2D game on mobile devices with sprites as my "characters." In the game, you must be able to touch the screen on the sprite to make it bounce. I have tried using Physics.Raycast and RaycastHit, but they fail to work correctly. I believe it may be because the RaycastHit isn't working with my BoxCollider. Maybe and I should be using something else that the Raycast will be able to collide with. Here is the code for the collision:
var hit : RaycastHit; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit)) { gravity = 0; gravity += 0.35; randGravity = Random.Range(0.005, 0.015); text++; }
I feel like this is a very basic issue and the answer is right in front of me, although I cannot find it. This is my first project working with Unity and I will greatly appreciate any help given to me. Thank you! :)