Simple Javascript question.

I have a code that makes 2 certain UI Images appear when certain buttons are pressed. Here’s the script…

var Weapon1 :UnityEngine.UI.Image;
var Weapon2 :UnityEngine.UI.Image;

function Start () {
    Weapon1.enabled = true;
    Weapon2.enabled = false;
}

function Update () {
    if (Input.GetKeyDown ("1"))
        if(Weapon2.enabled == true){
         Weapon1.enabled = true;
         Weapon2.enabled = false;
    }
    if (Input.GetKeyDown ("2"))
       if (Weapon1.enabled == true){
        Weapon2.enabled = true;
        Weapon1.enabled = false;
       
       
         }
    }

What would I put instead of…

UnityEngine.UI.Image

…so that it would toggle these (I’m not sure what they’re called)…
2174259--143955--Screenshot (179).png

That’s the GameObject itself.

Thanks, but now I have a problem. Whenever I enter play mode. I get this error…

MissingFieldException: UnityEngine.GameObject.enabled
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter ()
Boo.Lang.Runtime.RuntimeServices.DoCreatePropSetDispatcher (System.Object target, System.Type type, System.String name, System.Object value)
Boo.Lang.Runtime.RuntimeServices.CreatePropSetDispatcher (System.Object target, System.String name, System.Object value)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey19.<>m__F ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
WeaponSwitchObject.Start () (at Assets/WeaponSwitchObject.js:5)

Why? I never got an error when I used it with things like UI

enabled doesn’t exist in GameObject - you have to use the SetActive method that I linked in my previous post.

Oh, okay. Afterwards, I did get this error though. I’ve never gotten this one before so I’m not sure what it means…

var Weapon1 :GameObject;
var Weapon2 :GameObject;

function Start () {
    Weapon1.SetActive (true);
    Weapon2.SetActive (false);
}

function Update () {
    if (Input.GetKeyDown ("1"))
        if(Weapon2.SetActive (true)){
         Weapon1.SetActive (true);
         Weapon2.SetActive (false);
    }
    if (Input.GetKeyDown ("2"))
       if (Weapon1.SetActive (true)){
        Weapon2.SetActive (true);
        Weapon1.SetActive (false);
       
       
         }
    }

Assets/WeaponSwitchMesh.js(11,38): BCE0026: ‘void’ cannot be used in a boolean context.

Assets/WeaponSwitchMesh.js(16,34): BCE0026: ‘void’ cannot be used in a boolean context.

Use activeSelf to check if something is active or not.

You’re trying to use a function that returns void in an if statement, but if statements can only use booleans.

–Eric