- Home /
BCE0019 Error
I am trying to check a variable from another script but it gives me an error saying that the variable that I am trying to check is not a member in UnityEditor.MonoScript. What is the problem here?
Script:
#pragma strict
public var BulletPrefab : Rigidbody;
public var barrelEnd : Transform;
var Pos1 : Vector3;
var Pos2 : Vector3;
var CanShoot = true;
var SMG : GameObject;
var IsWalking = false;
var Aim = false;
var ReloadScript : MonoScript;
function Update () {
Screen.lockCursor = true;
if(IsWalking == true){
SMG.animation.Play("Walk_SMG");
}
else
if(IsWalking == false){
SMG.animation.Stop("Walk_SMG");
}
if(Input.GetButton("w")){
CanShoot = false;
if(Aim == false){
IsWalking = true;
}
}
else
if(Input.GetButton("a")){
CanShoot = false;
if(Aim == false){
IsWalking = true;
}
}
else
if(Input.GetButton("s")){
CanShoot = false;
if(Aim == false){
IsWalking = true;
}
}
else
if(Input.GetButton("d")){
CanShoot = false;
if(Aim == false){
IsWalking = true;
}
}
else
if(!Input.GetButton("w")){
CanShoot = true;
IsWalking = false;
}
else
if(!Input.GetButton("a")){
CanShoot = true;
IsWalking = false;
}
else
if(!Input.GetButton("s")){
CanShoot = true;
IsWalking = false;
}
else
if(!Input.GetButton("d")){
CanShoot = true;
IsWalking = false;
}
if(Input.GetButton("Fire2")){
transform.localPosition = Pos2;
Aim = true;
IsWalking = false;
}
if(!Input.GetButton("Fire2")){
transform.localPosition = Pos1;
Aim = false;
}
if(Input.GetButtonDown("Fire1")){
if(ReloadScript.AmmoInClip > 0){
var BulletInstance : Rigidbody;
BulletInstance = Instantiate(BulletPrefab, barrelEnd.position, barrelEnd.rotation);
BulletInstance.AddForce(barrelEnd.forward * 8000);
}
else
if(ReloadScript.AmmoInClip == 0){
Debug.Log("Magazine is empty");
}
}
}
Code with improper indenting and large gaps of whitespace is very hard to read. Plus we need to know what line is generating the error. If you doubleclick on the error in the Console window, it will highlight the line with the error in $$anonymous$$ono. Edit your question and insert a comment on the line with the error.
Here's the line :
if(ReloadScript.AmmoInClip > 0){
We cannot answer you if you don't show us the ReloadScript.
Answer by robertbu · Jun 04, 2013 at 07:08 PM
MonoScript is an editor class and not what you want to use to refer to another of your scripts. If your other class is attached to a game object, and if you are initializing variables by dragging and dropping them in the Inspector, then you want to us the name of your script here. Let's say the script is called "Reload". You would do:
var reload : Reload;
Then you would drag and drop the game object with the Reload script attached onto this variable in the inspector. You would then call it:
if(reload.AmmoInClip > 0){