// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody>(); state = DonutStates.Waiting; startPos = transform.position; targetPos = transform.position + -transform.right * range; timer = frequency; }
// Update is called once per frame void Update() { timer -= Time.deltaTime; if (state == DonutStates.Waiting && timer <= 0) { state = DonutStates.Pushing; } else if (state == DonutStates.Pushed && timer <= 0) { state = DonutStates.Pulling; } if (state == DonutStates.Pushing && (transform.position - targetPos).sqrMagnitude <= 0.3f) { state = DonutStates.Pushed; timer = waitTime; } else if (state == DonutStates.Pulling && (transform.position - startPos).sqrMagnitude <= 0.3f) { state = DonutStates.Waiting; timer = frequency; } }