Can't hit my character with input touch and Raycast
Hello Everyone. I'm new to Unity development especially with Android devices. I have a camera in orthographic mode with an isometric map. My characters prefab are on the "InputTouch" layer.
I'm working for an android game and I'd like to know when a character is touched and then fire an "OnTouch" method so I tried to use a Raycast like this : if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { Ray ray = GetComponent<Camera>().ScreenPointToRay(touch.position); Debug.Log(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, ~touchInputMask.value)) { GameObject recipient = hit.transform.gameObject; if (touch.phase == TouchPhase.Began) { Debug.Log ("Touch!"); recipient.SendMessage("OnTouch", hit.point, SendMessageOptions.DontRequireReceiver); } } } }
This script is attached to the main camera. "touchInputMask" is the public parameter I set with the Unity Editor (so it's the InputTouch layer as well as my characters). I tried this as the value for the Physics.RayCast forth parameter, but just in case i had misunderstood this parameter I also tried touchInputMask.value, 1 << touchInputMask.value, ~(1<< touchInputMask.value). I truly can't figure out what to do. The only guess I have is about orthographic mode but I don't know what to change at all. Thank you for your help.
Your answer
Follow this Question
Related Questions
Unity script opens Windows Explorer. Why? 1 Answer
How to ignore touches on a layer 0 Answers
Android Touch delta delay 2 Answers
Latency with android touch 1 Answer
Raycast collision vs unity collision system ( 2D Android game). 1 Answer