Это мой сценарий < /p>
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;
}
}
< /code>
Когда я изменяюсь. Публичный холст для публичного GameObject < /p>
public GameObject myObject;
// Use this for initialization
void Start () {
myObject.enabled = false;
}
< /code>
in myobject.enabled-это красный текст
и скажем «Ошибка CS0131: левая сторона задания должна быть переменной, свойством или индексером» < /p>
Почему? Как изменить < /p>
public Canvas myCanvas;
< /code>
to < /p>
public GameObject myCanvas;
< /code>
с < /p>
myCanvas.enabled = false;
< /code>
Конечная ошибка. Потому что GameObject не нуждается в включении < /p>
Но вот мой настоящий сценарий < /p>
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 ();
for (int i = 0; i < vbs.Length; ++i) {
// Register with the virtual buttons TrackableBehaviour
vbs .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!");
}
}
< /code>
он работает, когда < /p>
public Canvas Model_1;
< /code>
с включенным.public GameObject Model_1;
< /code>
и < /p>
model_1.enabled=false;
< /code>
и < /p>
switch(vb.VirtualButtonName) {
case "btnLeft":
if (model_1.enabled)
model_1.enabled = false;
else
model_1.enabled = true;
< /code>
, потому что моя модель не только 1
, поэтому я могу изменить свой объект, как логик, если
if (model_1 false)
model_1 на
Щелкнуть Btnleft снова
(if model_1 on)
model_1 false
model_2 on
like a model_1)>
Подробнее здесь: https://stackoverflow.com/questions/367 ... ect-cs0117