【发布时间】:2021-03-16 12:20:03
【问题描述】:
我如何在统一按下特定按钮时启用和禁用敌人对象上的脚本
void OnButtonClick()
{
StartCoroutine(Cooldown());
GetComponent<FollowEnemy>().enabled = !GetComponent<FollowEnemy>().enabled;
}
【问题讨论】:
-
您的代码有什么问题?一般来说你应该缓存
GetComponent的结果