Ray ray = Camera.mainCamera.ScreenPointToRay(Input.GetTouch (0).position);
if (Physics.Raycast(ray, out hit))
But when I have a Box Collider 2D , the Ray doesn’t seem to hit, I tried using the Physics2D.Raycast but cannot get it also does not hit because its 2D ?
I'm trying to run a foreach loop through touches in a separate script. I need to access the objects that I tap and change color. Could you help me out?
Hi thank you for the code, i have a question for you, with this script if i continue to press the screen the code is “repeating”, the is a way to stop this, i mean i want to repeat my code but i want to tap again, i want to avoid that whit pressure the code is repeating…
In case anyone is wondering what this should be for Unity 2019.3, 1st make sure the Game Object has a 2D Collider component, then add the following script:
Thanks for sharing. I was using the same method in 3D and got stuck when I tried with 2D.
– immeasurHow do you access that colliding object? Like if I wish to change its color or destroy it?
– immeasurThis script is ideally attached to the object so you will have direct access, but for other collisions you have to use OnCollisionEnter2D , see this http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html
– noob101I'm trying to run a foreach loop through touches in a separate script. I need to access the objects that I tap and change color. Could you help me out?
– immeasurPost your question to the community with details on what are your trying to do , I am very new to unity myself
– noob101