Hello Everyone! I’m sixteen and I’m making my first game with unity . I’ve been following tutorials and learning about physics, colliders and stuff. Right now, I have two animated characters, both controllable, moving on the scene and I’ve reached the point where I have to make 2 players fight against each other and I just can’t come up with a way to get it done. It’d be awesome if you guys could give me some help.
Are you trying to get a logic behind this, or trying to translate your logic to code?
I’m a little stuck with coding, I have the health for the players, I just don’t know how to make them loose health if the other player “attacks” them. I can do most of the coding, but I need some help with how to make attacks and how to loose health
Okay, here is something you can start.
Create the most simple damage function like this (pseudocode) :
Damage(){
health–;
}
test it with mousebutton or keyboard in Update() like this:
if (input.mousebutton) {
Damage();
}
Next step is figuring out attack range. You can do this with Unity - Scripting API: Physics.Raycast for example.
So, if attack button is pressed, check if enemy is close enough. Code would look something like this:
if (input.mousebutton) {
if (dist < attackRange){
Damage();
}
}
If you find raycast too complicated, you can also use triggers:
http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers
Hey Thanks for helping, I had already come up with a way that works, I forgot to post that here . Anyway thanks a lot for this, and if you could take a look at this http://answers.unity3d.com/questions/722049/arrow-collisions-and-taking-health-when-it-collide.html and help me try to figure out what’s wrong I’d truly thank you