- Home /
Answer by FLASHDENMARK · May 09, 2011 at 06:51 PM
In basic it is pretty easy.
First you will need to make the script that stores the health and can be accessed by another scripts, so:
Add this to the enemy and name the script enemyHealth:
static var health = 100; //Or any other value.
//The you want to declare when the character dies and what will happen if he dose:
function Update ()
{
if(health <= 0)
{
// Let the character die
}
}
Then we would want to create a new script that hurts the enemy:
Put this on the camera:
var hit : RaycastHit; var damage = 10;
function Update () { Physics.Raycast(transform.position, transform.forward, hit, Mathf.Infinity);
if(hit.collider.tag == "enemy" && Input.GetButtonDown("Fire1")) //Add a tag to the player that is named "enemy" { enemyHealth.health -= damage; } }
This is untested so there may be errors.
there comes an error which is as followed "(10,5): BCE0005: $$anonymous$$ identifier: 'EnemyHealth'.s"
The script name and the name of the script inside the script HAS to be the same or else it wont work.
thank you ill test it out and if it works ill rate u. professnal orangelightning. :). gd boy
Answer by red 2 · May 09, 2011 at 06:47 PM
go check the fps tutorial. it already features such a simple AI, modify health and bullet damage values to get to your 20 hits.
http://unity3d.com/support/resources/tutorials/fpstutorial.html
Answer by jybrd · Feb 17, 2012 at 07:24 PM
I am having this same type of issue and the fps tutorial sounds like it no longer works with the new unity. Is there somewhere else to try and look? Or if someone is just willing to listen to my new issue and help me out that would be cool too.