Hi, I’m trying to make a simple controller but I keep screwing it up. This is my current code:
using UnityEngine;
using System.Collections;
public class Tile : MonoBehaviour
{
void Update()
{
StartCoroutine(Move(Input.GetAxis("Horizontal")));
}
IEnumerator Move(float direction)
{
transform.Translate(direction * GameController.GM.distanceDelta,0,0);
yield return null;
}
}
I’ve tried other approaches such as Vector lerps and changing position in update, but I can’t arrive at the needed behavior.
What I want the object with this script to do, is once an axis is changed for it to move to move 2f in that direction. The problem is that I always get a continuous movement every frame. For example when I press the Up arrow, I want the object to go 2 units up, or if I press the Left arrow for it to go 2 units left. Any ideas?