C# GameObject设置活动空错误
我有一个名为“雪”的游戏对象,基本上是一个粒子系统,我想做的是,当我的玩家通过激活雪的墙时,它开始禁用 为了做到这一点,我开始禁用游戏对象,正如我所说,当球与墙发生碰撞时,我想激活雪。 像这样:C# GameObject设置活动空错误,c#,unity3d,unity5,C#,Unity3d,Unity5,我有一个名为“雪”的游戏对象,基本上是一个粒子系统,我想做的是,当我的玩家通过激活雪的墙时,它开始禁用 为了做到这一点,我开始禁用游戏对象,正如我所说,当球与墙发生碰撞时,我想激活雪。 像这样: using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement; public class cameraChange : MonoBehaviour {
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class cameraChange : MonoBehaviour {
private Camera focusCamera;
private Camera mainCamera;
private MeshFilter WallTurn;
public GameObject snow;
// Use this for initialization
void Start () {
focusCamera = GameObject.Find("ModeCamera").GetComponent<Camera> ();
mainCamera = GameObject.Find("Main Camera").GetComponent<Camera> ();
WallTurn = GameObject.Find ("WallTurn").GetComponent<MeshFilter> ();
}
// Update is called once per frame
void OnTriggerEnter (Collider other) {
Debug.Log (snow);
if (other.gameObject.tag == "Player") {
focusCamera.enabled = false;
mainCamera.enabled = true;
WallTurn.transform.Rotate (0f, 0f, 180f);
snow.SetActive (true);
}
使用UnityEngine;
使用系统集合;
使用UnityEngine.UI;
使用UnityEngine.SceneManagement;
公共类摄像机切换:单一行为{
私人摄像机聚焦镜;
私人摄像机;
私家车;
公众游戏对象;
//用于初始化
无效开始(){
focusCamera=GameObject.Find(“ModeCamera”).GetComponent();
mainCamera=GameObject.Find(“主摄像机”).GetComponent();
WallTurn=GameObject.Find(“WallTurn”).GetComponent();
}
//每帧调用一次更新
无效对撞机(对撞机其他){
Log(snow);
如果(other.gameObject.tag==“玩家”){
focusCamera.enabled=false;
mainCamera.enabled=true;
WallTurn.transform.Rotate(0f、0f、180f);
snow.SetActive(true);
}
问题是,我没有将对象引用设置为对象的实例,我在inspector上分配了snow对象,并且在Debug.log中它检测到它是游戏对象,我做错了什么?您的
游戏对象snow
已声明但从未实例化
在对其使用
SetActive
之前使用实例化。您得到的是哪一行代码错误?如果您从编辑器中拖动它,那么它就不是snow.SetActive
。双击该错误,它会将您带到实际的错误行。错误不在我认为的位置,而是在墙上转弯处,但您能我不会说,如果我拖到检查器,你说snow.SetActive不起作用为什么?@FilipeCaxinas他的意思是,如果你从检查器正确连接了游戏对象,那么snow.SetActive
就不会有问题。@Keiwan这就是我的意思。@WallTurn的哪一行导致了这个问题?