I'm new to Unity, sorry in advance if this is question is basic, but I try'ed to look online for similar questions with avail of answers. I have a gameobject which has a forward movement, when a variable is set to true I want that gameobject to move back X amount of units, but when the set back false I want the gameObject tot return to that previous movement. What I coded makes the gameObject move forward, but when triggered by the variable it does not move back. Can you please tell me what I did wrong?
public MonsterTarget monTarget;
public BandageTarget banTarget;
public Transform target;
public float speed;
public float backSpeed;
public bool back;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
back = monTarget.targetMove;
if (target.position.x > -11)
{
target.Translate(speed, 0, 0);
if (back == true)
{
Debug.Log("MOVE BACK");
target.Translate(backSpeed, 0, 0);
}
monTarget.targetMove = false;
}
}