- Home /
How do i make a fighting system like in oblivion?
I have made a sword and a first person controller so far, but how do i make the character attack? Anyone know the script? And please a step by step tutorial. :P
Answer by e-bonneville · Apr 22, 2010 at 09:10 PM
Couple of things. First off, you should check out some tutorials over here and a scripting tutorial here to learn how to script. Also, the script for attacking would be fairly simple. Actually, you'll need two scripts. One for the player, and one for the enemy. So, enough talk. Here's the dough:
This is the script for your enemy:
//---Enemy script---
var healthPoints = 100;
function ApplyDamage (damage : int) { healthPoints -= damage; }
function Update () { if (healthPoints <= 0) { Destroy (gameObject); } }
function OnCollisionEnter(c : Collision) { if (c.gameObject == player) { enemy.ApplyDamage(15); } }
Here's the script to put on the player:
//---Player script--- var healthPoints = 100;
function OnCollisionEnter(c : Collision) { if (c.gameObject == enemy) { enemy.ApplyDamage(15); } }
function ApplyDamage (damage : int) { healthPoints -= damage; }
This takes away health whenever there is a collision between the player and the enemy. Also, although I'm willing to help you this time, please remember for the future that UnityAnswers isn't a place to ask for scripts. It's for help solving problems you might encounter while writing them.
And, this is only one way to script a fight. There are other, much more advanced scripts, but like I said, this isn't a place to ask for scripts.
"this isn't a place to ask for scripts" - it isn't? Then how come there's a write-my-code Tag? :)
Somebody, during boot-camp mode, wanted some scripts... lol :)
You'll also notice that almost all of those questions were voted down at least once. :)
Are there any tuts for 1st person (sword fighting in particular)
Your answer
![](https://koobas.hobune.stream/wayback/20220612183501im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Jump. Script. 1 Answer
A Car color Changer 0 Answers
How to make a character go forward FOREVER? 0 Answers
Shoot. Just Shoot 5 Answers
Help for muzzle flash script 1 Answer