- Home /
Question by
MartinAstrab32 · Apr 21 at 09:21 PM ·
timer
How can i run backward turn only for 3 seconds?
How can i run backward turn only for 3 seconds but it will still do it at random?
public class Obstacle : MonoBehaviour { public float speed = 3f; public float resetTimer = 1f;
public float maxRot = 0f;
Vector3 direction = Vector3.forward;
public void Start()
{
}
public void Update()
{
float timer = Random.Range(0, 3000);
Vector3 drift = transform.position;
drift += direction * speed * Time.deltaTime;
transform.position = drift;
transform.Rotate(maxRot, 0, 0);
if (timer > 0)
{
timer -= Time.deltaTime;
}
else
{
Debug.Log("turn");
timer = resetTimer;
if (direction == Vector3.forward)
{
direction = Vector3.back;
}
else
{
direction = Vector3.forward;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How do you save timer with PlayerPrefs? 1 Answer
Can't activate my timer for shooting script? 2 Answers
How to stop a countdown from counting down 1 Answer
Destroy happens immediately 1 Answer