我需要获取一个布尔值(存储在变量“bouclier”中),并将其应用于启用或禁用GameObject。
该变量在游戏对象Player中(此处为右下角):
我需要启用或禁用这个游戏对象("Bouclier01"):
为了实现这个功能,我将脚本附加到游戏对象“Bouclier01”上。以下是脚本内容:using UnityEngine;
using System.Collections;
public class ShowBouclier : MonoBehaviour {
public GameObject Bouclier01;
public bool bouclier;
// Use this for initialization
void Start () {
Bouclier01 = Bouclier01.GetComponent<GameObject>();
}
// Update is called once per frame
void Update () {
Bouclier01.enabled = false;
if (bouclier == true) {
Bouclier01.enabled = true;
}
}
}
我一定是漏掉了什么,因为这会出现这个错误信息:
有什么好的方法可以正确地完成这个任务吗?