zak666
1
Hi guys Need a hand with this glitch. I have player in the centre with 4 targets representing left right up down, when u press forward looks at target1. however when you hold forward it cycles through each target when it should only look at target 1 as its assigned to instead of looking at other targets.
u press up, looks at forwards target, you press left looks at left target, but it cycles when you hold down buttons when it shouldn’t.
public Transform target1;
public Transform target2;
public Transform target3;
public Transform target4;
void Update ()
{
if (Input.GetKey (KeyCode.UpArrow)) {
transform.Translate (Vector3.right * moveSpeed * Time.deltaTime);
transform.LookAt (target1);
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.Translate (-Vector3.right * moveSpeed * Time.deltaTime);
transform.LookAt (target2);
}
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
transform.LookAt (target3);
}
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate (-Vector3.forward * moveSpeed * Time.deltaTime);
transform.LookAt (target4);
}
}
Try using Input.GetKeyDown instead of Input.GetKey.
It will only call this on press rather than hold.