Hello -
Continuing to port my first game to Unity, I’ve noticed that many tutorials are based on the use of the computer keyboard and not touch input from a mobile device. That has stalled me a bit, since I am using touch input.
That said, I have a script for the buttons and a script for the player controller. I am convinced the script for the button works fine, but am stuck with the player controller. This is what I have in the player controller script thus far:
using UnityEngine;
using System.Collections;
public class PlayerShipControl : MonoBehaviour {
public float rotationspeed = 5f;
private Rigidbody2D rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
if (TouchJoyPad.Button01) {
transform.Rotate (0, 0, rotationspeed);
}
if (TouchJoyPad.Button02) {
transform.Rotate (0, 0, rotationspeed * -1);
}
if (TouchJoyPad.Button03) {
//insert code to move forward
}
}
}
I know I must create a variable to assign a speed. Ideally I should accelerate to a certain max speed when touch is pressed, and coast and stop when touch is released.
My object PlayerShip starts pointing up. How do I know its direction and how do I accelerate relative to its direction?
Thanks, regards,
Marcos