2 OnTriggerEnter Problem

Hello , i have one collider attached to the gameobject and it’s giving +5 fuel but i want to do another collider that will take -5 fuel this is my code ;

	}
	void OnTriggerEnter (Collider other ) {
		fuel +=5; 
			score +=1;
	
	}
	

	void OnTriggerExit (Collider other)  {
		Destroy(other.gameObject);
		
	}

How can i make other OnTriggerEnter or is there have other ways ?

Thanks.

You have to check what the Collider is attached to.

One way you can do this is by checking the name of the object. Assuming the collider is the child of the object:

void OnTriggerEnter (Collider other) {
  if(other.transform.parent.name == "fuel")
  {
    fuel += 5; 
    score += 1;
  }
  else if(other.transform.parent.name == "obstacle")
  {
    fuel -= 5;
  }
}

If the collider is just a component of the object, remove “.transform.parent”.

Use properties of the Collider argument passed into the method to determine what event to do E.G. give fuel or take away fuel depending on what you hit