I am trying to make a basic city builder game. I have this very basic CollisionSystem
and it’s working I want to add this script to my building prefab to see if any building collisions are overlapping. The problem is I can’t use
public CollisionSystem collisionSystem;
to call if isTouching
is true
or false
in my main BuildingPlacement
script because it only works for one building and should be set before starting the game. So, my question is how can I learn if isTouching
has become true
in any of my CollisionSystem
scripts to use in my main BuildingPlacement
script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollisionSystem : MonoBehaviour
{
public bool isTouching = false;
public void OnTriggerEnter(Collider col)
{
if (col.CompareTag("Building") || col.CompareTag("Obstacle"))
{
isTouching = true;
//Debug.Log("true");
}
//Debug.Log("OnTriggerEnter");
}
public void OnTriggerExit(Collider col)
{
if (col.CompareTag("Building") || col.CompareTag("Obstacle"))
{
isTouching = false;
}
//Debug.Log("OnTriggerExit");
}
}