- Home /
Duplicate Question
deactivating object from a different scene
so in this game i am making a level beating game so when you hit the finish line i would like to deactivate this colider from a diffent scene and i have no clue where to start iv been using this script to activate and deactivate things
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 () {
triggerCount--;
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");
break;
case Mode.Replace:
if (source != null) {
Object.Instantiate (source, targetGameObject.transform.position, targetGameObject.transform.rotation);
DestroyObject (targetGameObject);
}
break;
case Mode.Activate:
targetGameObject.active = true;
break;
case Mode.Enable:
if (targetBehaviour != null)
targetBehaviour.enabled = true;
break;
case Mode.Animate:
targetGameObject.animation.Play ();
break;
case Mode.Deactivate:
targetGameObject.active = false;
break;
}
}
}
void OnTriggerEnter (Collider other) {
DoActivateTrigger ();
}
}
thnxs in advance
Dave I guess, all the PlayerPrefs questions. As it says below "Search on here for 100s quetions about PlayerPrefs"
Also if you search on "object different scene" there are vast macthes
But, TBC I take no care in selecting which "reason" for closing questions. (I believe the first default in the popup is "duplicate" is that right?) There was an insane amount of moderation this morning (something like an hour ???) I'd rather someone else did it so I can drink but there it is.
Again (I think we were talking about this another day right man?) do not hesitate for even a second to re-open any closed questions if you even slightly think they should be open. Just click the button.
Follow this Question
Related Questions
JavaScript Level Loading Disable A Layer 1 Answer
Hello, Need some help with invoke methods!! 2 Answers
Disabling Collision Object 1 Answer
How do you disable a c# from a js script? 1 Answer
Auto Enabling and looping a script? 1 Answer