- Home /
how can i disable scripts trough another script?
my problem is that i when i run my script it only works on "Character Motor" and doesnt affect the other scripts..also the "FpsMouseLookYAxis" and the "FpsMouseLook" are suppose to turn on while the "Character Motor" and the "MouseLook" .... what am i doing wrong?
var script : FpsMouseLookYAxis;
var script1 : FpsMouseLook;
var script2 : MouseLook;
var script3: CharacterMotor;
function OnTriggerEnter (col : Collider) {
if(col.name == "Player")
script3 = GetComponent(CharacterMotor);
script3.enabled = false;
&&
script2 = GetComponent(MouseLook);
script2.enabled = false;
&&
script1 = GetComponent(FpsMouseLook);
script1.enabled = true;
&&
script = GetComponent(FpsMouseLookYAxis);
script.enabled = true;
}
Answer by fafase · Apr 05, 2012 at 08:39 AM
var script : FpsMouseLookYAxis;
var script1 : FpsMouseLook;
var script2 : MouseLook;
var script3: CharacterMotor;
function Start(){
script = GetComponent(FpsMouseLookYAxis);
script1 = GetComponent(FpsMouseLook);
script2 = GetComponent(MouseLook);
script3 = GetComponent(CharacterMotor);
}
function OnTriggerEnter (col : Collider) {
if(col.gameObject.name == "Player"){
script3.enabled = false;
script2.enabled = false;
script1.enabled = true;
script.enabled = true;
}}
Remember that disabling a script only disable what is in the Update function.
well i theres a problem .....it doesnt do anithing when it hits the collider
You're both missing a closing curly brace for the OnTriggerEnter function. But you've probably already fixed that in your actual code.
Is your object the player colliding with set to IsTrigger? Is your player named Player exaclty the same?
Your answer
Follow this Question
Related Questions
scripting is not working for words "true" & "false" 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
UNITY Scripting - True and False not working! 3 Answers
Physics2D.OverlapAreaAll/NoAlloc fails detecting object in puzzling manner 1 Answer
Set only one true 1 Answer