Find Objects in Trigger and Effect Player
I'm having a hard time with this. I have an object, it can be surrounded by 1 to 4 other objects. Depending on what those objects variables are set to, I'm have modifiers I want to put on the damage applied to the object. I can't figure out how to first of all, find out what objects are in the trigger, and then two, how to effect my modifiers based on what's in there.
Currently I have this, just to detect what is in the trigger. It doesn't seem to work. If it matters, the game does start with the objects already in the trigger. Is that a problem? I thought this code below would print the objects to the console so I could verify it's working, but it doesn't.
// Other Characters
public List<GameObject> others;
void OnTriggerEnter(Collider other)
{
if (other.tag == "character")
{
others.Add(other.gameObject);
Debug.Log(other.gameObject);
}
}
Answer by tormentoarmagedoom · Mar 05, 2020 at 10:40 AM
Hello.
I recommned you to read this:
https://docs.unity3d.com/Manual/ExecutionOrder.html
You can see the order of execution of all functions.
So, you can do something with this structure:
int NumberOfCloseObjects;
void FixedUpdate()
{
NumberOfCloseObjects = 0;
}
void OnTriggerStay()
{
if other = character
{
NumberOfCloseObjects++;
}
void Update()
{
// Here, each frame NumberOfCloseObjects variable value will be the number of object close
}
Make some tests and will find the solution!
Bye!
Your answer
Follow this Question
Related Questions
Bug? or nuance with trigger detection? 1 Answer
OnTriggerEnter2D works without RigidBody BUT only being in children 0 Answers
How to disable script on trigger 1 Answer
OnTrigerEnter not working 2 Answers