I'm designing a game that requires movement to be very precise. I want each step to take you the exact same distance, so the player can count footsteps in order to judge distance, as the game will take place in total darkness.
I've seen other answers to this problem that involve using coroutines, but those don't seem to work for me, and the original posters seem to be long gone without giving the real answer.
Heres where I am with this so far based on those solutions.
public class Movement : MonoBehaviour {
public GameObject player;
public float speed;
// Use this for initialization
void Start () {
//Coroutine for movement
StartCoroutine(CoUpdate());
}
IEnumerator CoUpdate()
{
if(Input.GetKey(KeyCode.UpArrow))
{
move(Vector3.forward);
yield return null;
}
else if(Input.GetKey(KeyCode.DownArrow))
{
move (Vector3.back);
yield return null;
}
}
void move(Vector3 direction)
{
transform.Translate (direction * speed, Space.Self);
}
}
I intend to make left and right do exact 90 degree turns in those directions, thats why those directions aren't currently present.
Help with this problem would be greatly appreciated
↧