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
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.