【发布时间】:2020-08-31 19:56:28
【问题描述】:
我正在使用 Unity 引擎 2019.3.9f1。现在我正试图通过 SetActive(false) 隐藏一个对象,但也许我做错了,或者没有预料到什么。
现在我在场景中有一个名为“TILE_LARGE_1”的游戏对象。
通过按键盘上的“D”,我想使用 SetActive(false) 隐藏对象。脚本编译得很好,但是当我按“D”时,对象并没有隐藏。使用这种方法有什么我不知道的警告吗?
using UnityEngine;
using System.Collections;
[AddComponentMenu("Utilities/VisObjects1")]
public class VisObjects1 : MonoBehaviour
{
public GameObject TILE_LARGE_1;
void Start()
{
TILE_LARGE_1.SetActive(true); // false to hide, true to show
}
void Update()
{
if (Input.GetKeyDown(KeyCode.D))
{
TILE_LARGE_1.SetActive(false); // false to hide, true to show
}
}
}
【问题讨论】: