Hi there So basically I need a platform’s health to decrease over time as characters are stood on it, but then stop decreasing as they walk off of it. How could I go about this efficiently as there could be many characters stood on it at once?

Hello ! You can first of all make a box collider that could serve as a trigger zone . In the component you enable the Is Trigger option. Therefore, you could get the health of the character that has a collider that’s in the trigger zone to decrease. You can resize the box collider to fit your needs

First off, you can attach a collider to the platform, and then make a script for it to detect when things enter or leave the platform. You can do this with the OnCollisionEnter and OnCollisionExit functions.

Make an int variable to store the number of players currently on the platform, and make sure any player objects are tagged as Player, then you could try something like this:

void OnCollisionEnter(Collider other){      //checks when an object collides with the platform
   if(other.gameObject.tag == "Player"){    //checks if the other object is tagged as a Player
      playersOnPlatform ++;                 //this is the int variable which whould be declared at the top of the script. It adds 1 to this value every time a player steps onto the platform.
   }
}

void OnCollisionExit(Collider other){       //checks when an object leaves the platform
   if(other.gameObject.tag == "Player"){    //if that object is a player
      playersOnPlatform --;                 //subtract 1 from the variable
   }
}

This is untested code but it should work :slight_smile: Once you have that working, you can then use the variable (“playersOnPlatform”) to calculate the health loss of the platform. You could try something like this in your Update:

void Update(){
   if(playersOnPlatform > 0){        //if there are any players on the platform
      currentPlatformHealth -= ((damagePerSecond*Time.deltaTime)*playersOnPlatform); //do X damage to the platform per second, multiplied by the no. of players
   }
}

So, you’d have a variable containing the platform’s current health (currentPlatformHealth), and then you’d have one containing the damage (damagePerSecond) which is how much health the platform would lose each second.

Now if the platform has players on it, it will reduce the platform health at the damagePerSecond rate multiplied by the no. of players on it.

Hope that helps :slight_smile: