using System.Collections.Generic;
using UnityEngine;
public class triggerForMasterSpawner : MonoBehaviour
{
public spawnerScript spawnHim;
void Start()
{
spawnHim = GetComponent<spawnerScript>();
}
void OnTriggerEnter2D(Collider2D insideObject)
{
if (insideObject.tag == "barg")
{
spawnHim.enabled = false;
Debug.Log("BOSS IS HERE!!!");
}
else if (spawnHim == null)
{
Debug.Log("wtf is happening");
}
}
void OnTriggerExit2D(Collider2D leaveObject)
{
if(leaveObject.tag != "barg")
{
spawnHim.enabled = true;
Debug.Log("BOSS HAS LEFT!!!");
}
else if (spawnHim == null)
{
Debug.Log("wtf is happening");
}
}
void Update()
{
}
}```
I'm trying to enable a spawner whenever my boss leaves the check area and disable the spawner whenever the boss enters. I have a 2D collider covering the play area to check for the boss, both colliders are set to trigger, and one has a rigidbody2D. The errors happen at spawnHim.enabled = false; and spawnHim.enabled = true;
#Object reference error with OnTriggerExit2D and Enter2D
1 messages · Page 1 of 1 (latest)