this is my script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class MouseDownText : MonoBehaviour {
public Canvas myCanvas;
// Use this for initialization
void Start () {
myCanvas.enabled = false;
}
// Update is called once per frame
void Update () {
}
void OnMouseDown()
{
// for switch on/off
if (myCanvas.enabled)
myCanvas.enabled = false;
else
myCanvas.enabled = true;
}
}
when i change. public Canvas to public GameObject
public GameObject myObject;
// Use this for initialization
void Start () {
myObject.enabled = false;
}
in myObject.enabled is red text and say "error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer"
why ?
UPDATE QUESTION -------
top question just how to change
public Canvas myCanvas;
to
public GameObject myCanvas;
with
myCanvas.enabled = false;
sure error. because gameobject no need Enabled
but here is my real script
using UnityEngine;
using System.Collections.Generic;
using Vuforia;
public class VirtualButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler {
// Private fields to store the models
public Canvas model_1;
void Start() {
// Search for all Children from this ImageTarget with type VirtualButtonBehaviour
VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour> ();
for (int i = 0; i < vbs.Length; ++i) {
// Register with the virtual buttons TrackableBehaviour
vbs [i].RegisterEventHandler (this);
}
model_1.enabled=false;
}
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) {
//Debug.Log(vb.VirtualButtonName);
Debug.Log("Button pressed!");
switch(vb.VirtualButtonName) {
case "btnLeft":
if (model_1.enabled)
model_1.enabled = false;
else
model_1.enabled = true;
break;
// default:
// throw new UnityException("Button not supported: " + vb.VirtualButtonName);
// break;
}
}
/// Called when the virtual button has just been released:
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) {
Debug.Log("Button released!");
}
}
it work when
public Canvas Model_1;
with Enabled.
but how when i want change Canvas to GameObject ?
what must i change in here
public GameObject Model_1;
and
model_1.enabled=false;
and
switch(vb.VirtualButtonName) {
case "btnLeft":
if (model_1.enabled)
model_1.enabled = false;
else
model_1.enabled = true;
because my model it not just 1 so i can change my object like LOGIC if if(model_1 false) model_1 on click BtnLeft again (if model_1 on) model_1 false model_2 on like a next object