【发布时间】:2016-04-21 08:41:45
【问题描述】:
这是我的脚本
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;
}
}
当我改变时。公共画布到公共游戏对象
public GameObject myObject;
// Use this for initialization
void Start () {
myObject.enabled = false;
}
在 myObject.enabled 中是红色文本 并说“错误 CS0131:赋值的左侧必须是变量、属性或索引器”
为什么?
更新问题-------
最重要的问题是如何改变
public Canvas myCanvas;
到
public GameObject myCanvas;
与
myCanvas.enabled = false;
确定错误。因为游戏对象不需要启用
但这是我的真实脚本
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!");
}
}
它在什么时候起作用
public Canvas Model_1;
启用。
但是当我想将 Canvas 更改为 GameObject 时如何?
我必须在这里改变什么
public GameObject Model_1;
和
model_1.enabled=false;
和
switch(vb.VirtualButtonName) {
case "btnLeft":
if (model_1.enabled)
model_1.enabled = false;
else
model_1.enabled = true;
因为我的模型不只是 1 所以我可以像 LOGIC 一样改变我的对象 如果(模型_1 假) model_1 开启 再次单击 BtnLeft (如果 model_1 开启) 模型_1 假 model_2 开启 像下一个对象
【问题讨论】:
标签: c# unity3d augmented-reality vuforia