Reputation: 543
I need to turn off a script from another script in Unity
. The script is in C#
and the script I am turning off is in JS
. Both scripts are attached to the same object. The error I am receiving says that there is no such thing as enabled. Any thoughts? Below is part of my code.
void Update ()
{
var walkScript = GameObject.FindWithTag ("Player").GetComponent ("CharacterMotor");
if ((Input.GetKey ("p")) && (stoppedMovement == true)) {
stoppedMovement = false;
walkScript.enabled = true;
} else if ((Input.GetKey ("p")) && (stoppedMovement == false)) {
stoppedMovement = true;
walkScript.enabled = false;
}
The error I am recieving is as follows:
Assets/Standard Assets/Character Controllers/Sources/Scripts/MouseLook.cs(41,36): error CS1061: Type
UnityEngine.Component' does not contain a definition for
enabled' and no extension methodenabled' of type
UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)
Upvotes: 1
Views: 1984
Reputation: 524
The class Component doesn't have a property enable. Try
Behaviour walkScript = (Behaviour)GameObject.FindWithTag ("Player").GetComponent ("CharacterMotor");
Assuming it is a behaviour.
Upvotes: 4