Hello, So I have a player object, and the player object moves straight, However I have another object that Instantiates every 5-10 seconds, this is just a wall, and the wall has an opening for the player to maneuver in to avoid getting damaged/hit. the Wall has a parent, which is the entire wall that has the box collider “Collision”, and a child object, that has the collider “Opening”, the hard part is, finding the right, IF else statement, to IF the player collides with BOTH opening AND collision, then that’s a hit, and no points… BUT if it collides with ONLY the opening, then reward a point… again, trying to find the right combo… is difficult, I have the code below, any ideas, thoughts, examples help, I would greatly appreciate it.
public void OnTriggerEnter(Collider other)
{
// Check if the object hit Collider A
if (other.gameObject.name == "Square_Colider") // this is the Collider block wall player avoids
{
collidingDamage = true;
}
// Check if the object hit Collider B
if (other.gameObject.name == "Square_Opening") // this is the opening box collider player needs to go through
{
opening = true;
//Debug.Log("Entered Collider Opening");
//// If only Collider B is triggered, score a point
if (!collidingDamage)
{
MainG.AddScore(); // public static Int to add score IF avoided the block wall
}
}
// If both A and B are hit, apply damage
if (collidingDamage && opening)
{
StartCoroutine(Shaking());
}
if (!collidingDamage)
{
if (opening)
{
MainG.AddScore();
}
}
//This is trying to reset... but doesnt seem to work.
private void OnTriggerExit(Collider other)
{
// Reset when exiting Collider A
if (other.gameObject.name == "Square_Colider(Clone)")
{
collidingDamage = false;
Debug.Log("Exited Collider A");
}
// Reset when exiting Collider B
if (other.gameObject.name == "Square_Opening")
{
opening = false;
Debug.Log("Exited Collider B");
}
}