Hi, I wanted to ask, does anyone know how to call a GameObject in a script, and the use its trigger?
I tried doing something, and I know that the code looks stupid, but it shows what I want to do.
The code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FirstBoss : MonoBehaviour
{
public GameObject BossTrigger;
^ This is assuming you’ve set the bossObject within the inspector, so no GetComponent() calls would be needed. However If you haven’t set it in inspector, or the way you game works you can’t initially declare it, because it doesn’t exist at start? Then within OnTriggerEnter:
^ Would work. But this is slow and sometimes will throw errors if the boss were to die from another factor(as I have found in some cases). So it is best to cache the bossClass as a reference(easiest way is to set it within the inspector) normally as a class, and using GetComponent() within the start method.
Then a simple check to verify that object collider in which was triggered, is that class and can have it’s TakeDamage() function work