Log in or register to post comments

Activate and Deactivate Trigger

December 25, 2012 - 5:53pm #1

I have two GameObject, One with an Activate Trigger and the other One with a Deactivate Trigger. My 3D Object have a SmoothLookAt script to look at the camera, when the camera Activate Trigger the 3D object start to follow the camera, then the camera goes to the Deactivate Trigger then the 3D object stop right on the position where the camera touch the GameObject with the Deactivate Trigger.
I need that when the camera touch the Deactivate Trigger, the 3D object goes back to their original position, and not stays looking beside. How can i figure that.



  1. http://forum.unity3d.com/images/styles/influx/style/altBG.gif); background-attachment: scroll; background-color: rgb(254, 254, 254); float: left; width: 938px; background-position: 0% 100%; background-repeat: repeat no-repeat; ">
    here is the script attach to the GabeObject Deactivate Trigger. I need the 3D object goes back to their original position, and not stays looking beside.

    using UnityEngine;

    public class ActivateTrigger : MonoBehaviour {
    public enum Mode {
    Trigger = 0, // Just broadcast the action on to the target
    Replace = 1, // replace target with source
    Activate = 2, // Activate the target GameObject
    Enable = 3, // Enable a component
    Animate = 4, // Start animation on target
    Deactivate= 5 // Decativate target GameObject

    /// The action to accomplish
    public Mode action = Mode.Activate;

    /// The game object to affect. If none, the trigger work on this game object
    public Object target;
    public GameObject source;
    public int triggerCount = 1;///
    public bool repeatTrigger = false;

    void DoActivateTrigger () {

    if (triggerCount == 0 || repeatTrigger) {
    Object currentTarget = target != null ? target : gameObject;
    Behaviour targetBehaviour = currentTarget as Behaviour;
    GameObject targetGameObject = currentTarget as GameObject;
    if (targetBehaviour != null)
    targetGameObject = targetBehaviour.gameObject;

    switch (action) {
    case Mode.Trigger:
    targetGameObject.BroadcastMessage ("DoActivateTrigger");
    case Mode.Replace:
    if (source != null) {
    Object.Instantiate (source, targetGameObject.transform.position, targetGameObject.transform.rotation);
    DestroyObject (targetGameObject);
    case Mode.Activate:
    targetGameObject.active = true;
    case Mode.Enable:
    if (targetBehaviour != null)
    targetBehaviour.enabled = true;
    case Mode.Animate:
    targetGameObject.animation.Play ();
    case Mode.Deactivate:
    targetGameObject.active = false;

    void OnTriggerEnter (Collider other) {
    DoActivateTrigger ();


Log in or register to post comments