How do I use the rear touch pad? I want to use it so it'll work in place of the mouse in this script: using UnityEngine; using System.Collections; public class Rotate: MonoBehaviour { public int rotationOffset = 90; void Update () { Vector3 difference = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position; difference.Normalize (); float rotZ = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler (0f, 0f, rotZ + rotationOffset); } }
The rear touch pad is implemented through the UnityEngine.PSM.PSMInput class. For example, to iterate through each of current touch you would use the code: using UnityEngine.PSM; void OnGUI () { foreach (Touch touch in PSMInput.touchesSecondary) { Vector2 pos = touch.position; GUI.Label(new Rect(pos.x, Screen.height - pos.y, 50, 30), "(X) #" + touch.fingerId); } }
Thanks for the help, but because I'm a C# noob, I don't know how to use this in place of the mouse for my script.
Maybe try something like this: Code (csharp): using UnityEngine; using System.Collections; using UnityEngine.PSM; public class Rotate : MonoBehaviour { public int rotationOffset = 90; void Update() { foreach (Touch touch in PSMInput.touchesSecondary) { if (touch.fingerId == 0) { Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; difference.Normalize(); float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset); } } } }
Thanks, DanielSnd! I have one last question, but it's so small and easy that I don't think it would be a good idea to create a new thread for it. I want to know how I can use the right joystick for my rotation script. I figured out why almost no games (I've played) use the rear touch pad.
Set those on your Input Manager Code (csharp): using UnityEngine; using System.Collections; using UnityEngine.PSM; public class Rotate : MonoBehaviour { public int rotationOffset = 90; void Update() { // See InputManager (Edit > Project > Input) for mapping from <string> to <axis> float x = Input.GetAxis("RightStickH"); float y = Input.GetAxis("RightStickV"); Vector3 difference = new Vector3(x, y, 0); float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset); } }