C# Player Health System In unity

Can someone help me with the formatting on a script?
I know exactly what I want to happen but I don’t really know how to code. I was hoping someone could make this script for me so I can see the realistic format that applies to what I am trying to do.
Basically I want a self standing script that can be reused many times.
The Idea is that if one game object comes into contact with the other it starts to take enemyDamage which is playerDamage once per second(not sure how to implement seconds). playerDamage is a simple public variable predefined on the script, say 5. There is the health variable, let’s say 100. so here is the path:
if collision = true
then apply enemyDamage
enemyDamage = playerDamage(get playerDamage from colliding object)
health = 100
playerDamage=5

I am not sure how to check if two objects are colliding or not. Would I have to split this script into more than one script to fit in collision?

Only if the object this script is on doesn’t have a collider attached.

In order to detect collision you need to have two objects with colliders (one of which must have a rigidbody attached).
If you want to use triggers (if you dont want a sword to stop once it hits an object, but rather pass through it)
OnTriggerEnter
OnTriggerExit

If you do want collision:
OnCollisionEnter
OnCollisionExit

For more information on how to work with collision and physics overall:
Collider
Physics
Rgidbody

Physics.Raycast
Vector3.Distance
Vector3.Angle

BoxCollider
SphereCollider
CapsuleCollider
MeshCollider

thanks mcmayhem :slight_smile: