Unity让其他物体的脚本禁用
时间: 2024-01-22 10:21:10 浏览: 20
你可以使用以下代码禁用其他物体上的脚本:
```
// 获取其他物体的脚本
var otherScript = otherGameObject.GetComponent<OtherScript>();
// 禁用脚本
otherScript.enabled = false;
```
在这里,`otherGameObject` 是你想要禁用脚本的物体的引用,`OtherScript` 是你想要禁用的脚本的类型。使用 `GetComponent()` 方法获取其他物体上的脚本实例,然后将 `enabled` 属性设置为 `false` 来禁用脚本。