Search Unity

How to check variable on obj I triggered

Discussion in 'Visual Scripting' started by Vikoman, Aug 21, 2022.

  1. Vikoman

    Vikoman

    Joined:
    Aug 21, 2022
    Posts:
    1
    Hi I'm doing a game whre you have randomly generated dungeon and I want to check if the spawnpoint that spawns rooms has variable "spawned" set to false. I used GetComponent to do this and it is giving me "NullReferenceException" error. Is there anyone who could help me?
    I'm following this tutorial to do the dungeon generation:

    And I'm getting that error after he coded the closedRoom spawn part.


    Code (CSharp):
    1.  
    2. void OnTriggerEnter(Collider other)
    3.     {
    4.         roomSpawner = other.gameObject.GetComponent<RoomSpawner>();
    5.         if (other.CompareTag("SpawnPoint"))
    6.         {
    7.           if(other.GetComponent<RoomSpawner>().spawned == false && spawned == false)
    8.             {
    9.                 Instantiate(templates.closedRoom[1], transform.position, Quaternion.identity);
    10.                 Destroy(gameObject);
    11.             }
    12.             spawned = true;
    13.         }
    14.  
    15.  
    16.    
     
    Last edited: Aug 22, 2022