- Home /
OnTriggerEnter launching a delayed tween
I am trying to set up the following: a box collider that serves as a trigger, which when the player enters triggers a tween path after a further preset delay. The code I have below starts the code regardless of whether the player has entered the trigger or not, i.e. as soon as you enter Play Mode, the delay countdown begins. Any help would be hugely appreciated - I've tried formatting things around every way I can think of, and this is the closest I've come:
using UnityEngine;
using System.Collections;
using DG.Tweening;
public class Move : MonoBehaviour
{
public int laps = 1;
public float speed = 10f;
public int delay = 1;
public Transform target;
public PathType pathType = PathType.Linear;
public Vector3[] waypoints = new[]
{
new Vector3 (0, 0, 0),
new Vector3 (5, 0, 0),
new Vector3 (5, 0, 5),
new Vector3 (0, 0, 5)
};
void OnTriggerEnter()
{
StartCoroutine ("wait");
}
IEnumerator Start()
{
{
yield return new WaitForSeconds (delay);
StopCoroutine ("wait");
}
Tween t = target.DOPath (waypoints, speed, pathType)
.SetOptions (true)
.SetLookAt (0.001f);
t.SetEase (Ease.Linear).SetLoops (laps);
}
}
Answer by barbe63 · Jul 10, 2015 at 01:43 AM
Start is a reserved name that is launched after Awake() in MonoBehavior Class even if it's an IEnumerator. Just rename it.
$$anonymous$$any thanks! That was the problem; I also didn't need the Coroutine, for anyone else having similar issues.
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D/OnCollisionEnter2D - delay 1 Answer
Waiting for fractions of a Second 1 Answer
Multiple Cars not working 1 Answer
I want to create a pause in between spawning objects in a row 2 Answers
Wait for seconds question 1 Answer