Damage or Kill the player?

Shizane

New member
I've been looking for a tutorial on how to damage the player. What script do I attach to my "bullet" to kill the player? I have the Die and Health on my player but not sure how to kill him.

This is with Emerald AI. I just wanted to attach a script to the AI's bullet for the damage without setting up an item for the AI.

Cheers.
 
Last edited:
You need to get the Health component of the target, then you can call Health.Damage or Health.ImmediateDeath. See this page for more info on the Health component:

 
So i cant seem to take damage evin tho the ai is attacking showing damage numbers and causing blood to appear any reason im not dieing>?
 
Blood can be added using the surface system. A UI damage amount is not included in the controller.
 
Im not a coder by any means how do you go about making a universal scrip that i can put on something as a example a trap that swings when the collider connects with the players collider do X damage and it would be amazing if i could change the input in unitys inspector like you guys have UCC setup
 
You could use OnCollisionEnter on the trap object, check if the collision is with the player, and apply the damage accordingly. A simple untested example as a starting point:

C#:
void OnCollisionEnter(Collision collision) {
    var health = collision.transform.GetComponentInParent<CharacterHealth>();
    if (health == null) return;
    
    health.Damage(50);
}
 
No idea if i take that code and put it into a a script i just get errors .. damn i wish the demo had something with nolan taking damage from touching it
 
You'd have this script on your trap object with its own collider. You will however need a basic level of knowledge with Unity scripting to start creating custom things like traps etc.
 
I dont understand how that could be a hard script to do when a player touches this collider do X damage... bummer this isnt in the demo that seems to me a simple thing but ill keep looking
 
The script I just pasted above is pretty much all you'd need, along with the trap object itself with a collider. The only other thing you'd need is a way to have the trap itself actually moving.
 
It gives me a error saying name (CharacterHealth) could not be found.
i have traps and ones that move i just need something to deal damage to the player on contact.
 
You'll need to make sure to include the namespace of CharacterHealth in your script. If you open up CharacterHealth.cs, and look at the top of the script, you'll see namespace Opsive.UltimateCharacterController.Traits - this describes the namespace that the CharacterHealth class exists in. So, at the top of your script, you'll need to put using Opsive.UltimateCharacterController.Traits; to access that namespace.
 
Top