I am calling a function from a different script script and I am getting this error "NullReferenceException: Object reference not set to an instance of an object PlayerCollision.OnTriggerEnter (UnityEngine.Collider collision)" What do I do? This is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCollision : MonoBehaviour
{
void OnTriggerEnter(Collider collision)
{
if(collision.gameObject.CompareTag("BlackSnow"))
{
GameManager.Instance.blackSnowEvent(collision.gameObject);
}
}
}
this is the code in the script where the function is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public ParticleSystem blackSnowParticleSystem;
private bool snowActivated = false;
public int duration = 5;
#region Singleton
private static GameManager instance;
public static GameManager Instance
{
get
{
return instance;
}
}
void Start()
{
}
IEnumerator wait(int arg){
yield return new WaitForSeconds(arg);
}
public void blackSnowEvent(GameObject snowTrigger){
if(snowActivated == false){
snowActivated = true;
snowTrigger.SetActive(false);
blackSnowParticleSystem.Play();
Debug.Log(duration);
StartCoroutine(wait(duration));
blackSnowParticleSystem.Stop();
snowActivated = false;
}
}
#endregion
}