Stop moving gameObject and push it back
I'm new to Unity sorry if this is a stupid question, I have a gameObject that is moving forward, when a collider is hit a variable is set true and the gameObject will move backwards. When the variable is then set false the gameObject should return moving forward. My gameObject only moves forward, when the collider is hit and the variable is set true, the object is not moving back. Can you please tell me what I'm doing 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;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Make object move back and forth 2 Answers
how can I move an object around a parent object manually? 0 Answers
Player teleport not working 0 Answers
How to move gameObject along a Vector3 with OnMouseDrag()? 0 Answers
Scene Changing changes speed of objects 0 Answers