Question by
Windyone · Feb 08, 2017 at 06:44 AM ·
scripting problemerrorerror messagescripting beginner
An instance of type 'UnityEngine.Behaviour' is required to access non static member 'enabled'.
Hi, I got the error in the title when I tried to disable a Animation component. All I need to know is how to put ' UnityEngine.Behaviours ' into my script.
Here's My Code:
var MuzzelFlashGo : GameObject;
var NoAnimationGO : GameObject;
function Start () {
Animation = gameObject.GetComponent("Animation");
Animation.enabled = false;
}
function Update () {
if(Input.GetButtonDown("Fire1")) {
var gunsound : AudioSource = GetComponent.<AudioSource>();
gunsound.Play();
MuzzelFlashGo.SetActive(true);
MuzzelFlashStop();
GetComponent.<Animation>().Play("GunShot");
GlobalAmmo.LoadedAmmo -= 1;
}
if (Input.GetButtonDown("Fire1")) {
if (GlobalAmmo.LoadedAmmo < 0) {
GlobalAmmo.LoadedAmmo += 1;
}
if (Input.GetButtonDown("Fire1")){
if (GlobalAmmo.LoadedAmmo < 0)
NoAnimation();
}
}
}
function MuzzelFlashStop() {
yield WaitForSeconds (0.1);
MuzzelFlashGo.SetActive(false);
}
function NoAnimation() {
Animation.enabled = false;
}
All I need to know is how to put 'UnityEngine.Behaviours' into my script.
Comment
don't use Animation as a variable name, because it's also a class in unity.
where is that variable you assign to in Start declared anyway?
I don't quite understand what you mean there. I am only a beginner but there is no variable in Start is there? I don't know.
function Start(){
GetComponent.<Animator>().enabled = false;
}
same goes for the last function you've written