Created
December 27, 2015 18:11
-
-
Save dentedpixel/582bbaa0e0cabb2e5112 to your computer and use it in GitHub Desktop.
Trigger Points Along LeanTween Path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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