0

i have a gameObject called snow, that basicly is a particleSystem, what i want to do is, when my player pass trough a wall active the snow, it starts disabled.

To do that i started the gameobject disabled as i said, and when the ball colides with the wall i want to activate the snow. Like this:

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);

    }

the problem is that i get this error Object reference not set to an instance of an object, i assigned the snow object on the inspector, and in the Debug.log it detects that it is a gameobject, what am i doing wrong?

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Which line of code are you getting that error? If you dragged it in from the Editor then it is not `snow.SetActive`. Double click on that error and it will take you to the actual error line. – Programmer Jan 07 '17 at 10:53
  • well the error was not where i thaught, it was on the WallTurn, but can you just say, if i draged to the inspector you said that snow.SetActive wouldn't work why? –  Jan 07 '17 at 11:03
  • 1
    @FilipeCaxinas He meant that `snow.SetActive` can't be the problem if you correctly connected the GameObject from the Inspector. – Keiwan Jan 07 '17 at 11:13
  • @Keiwan That's what I meant. – Programmer Jan 07 '17 at 11:14
  • @Which line of WallTurn is causing that problem? – Programmer Jan 07 '17 at 11:15
  • Is your WallTurn Gameobject actually called "WallTurn" in the Scene? Maybe you've acidentally misspelled it. – Keiwan Jan 07 '17 at 11:16

1 Answers1

0

Your GameObject snow is declared but never instanciated.

Use https://docs.unity3d.com/ScriptReference/Object.Instantiate.html to instantiate before using SetActive on it.

Arnaud F.
  • 8,252
  • 11
  • 53
  • 102