Skip to content

Instantly share code, notes, and snippets.

@dentedpixel
Created December 27, 2015 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dentedpixel/582bbaa0e0cabb2e5112 to your computer and use it in GitHub Desktop.
Save dentedpixel/582bbaa0e0cabb2e5112 to your computer and use it in GitHub Desktop.
Trigger Points Along LeanTween Path
using UnityEngine;
using System.Collections;
public class TriggerPointExample : MonoBehaviour{
private GameObject light;
void Awake(){
light = gameObject.transform.Find("Spotlight").gameObject;
light.SetActive( false );
}
void OnTriggerEnter(Collider info) {
light.SetActive( true );
}
void OnTriggerExit(Collider info) {
light.SetActive( false );
}
}
public class LTPathExampleTriggers : MonoBehaviour {
public GameObject prefabLightPost;
public LeanTweenPath ltPathDefinition;
private LTBezierPath ltBezierPath;
private float iter;
void Start () {
// Create a LTBezierPath from the array of vectors made with the LeanTween Editor
ltBezierPath = new LTBezierPath( ltPathDefinition.vec3 );
// Adding Light Posts
for(int i = 0; i < ltBezierPath.pts.Length; i++){
// Add a Trigger at each bezier control node (which is every fourth point)
if(i%4==0){
GameObject post = GameObject.Instantiate( prefabLightPost );
post.AddComponent<TriggerPointExample>(); // This component will track the entering and exiting of the car along the path
post.transform.position = ltBezierPath.pts[ i ];
}
}
}
void Update () {
ltBezierPath.place( transform, iter );
iter += Time.deltaTime * 0.03f;
if(iter>1.0f)
iter = 0.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment