Hi, I am working on a runner game where you try to dodge obstacles. What I am trying to do is on a single key press it changes directions. So if it is going left then key press it goes left and vice versa. I made a code but the problem is that it won’t switch directions. If you could, please look over and tell what is wrong with the code.
using UnityEngine;
using System.Collections;
public class Main : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Rotate()
{
transform.Rotate(Vector3.back * -20);
}
void Update () {
int speed = 1;
int move = 1;
if (move == 1)
{
transform.Translate(Vector3.right * Time.deltaTime * speed);
}
if (move == -1)
{
transform.Translate(Vector3.left * Time.deltaTime * speed);
}
if(Input.GetKey("space"))
{
move = move * -1;
}
}
}
P.S.
Later I want to make it an app. So how do I set it up so that if you tap the screen(anywhere on the screen) the character will switch directions. Thanks!