- Home /
Generating enemies dynamically to be attached to enemt prefab
Hello everyone...
i been trying to figure out this issue for few hours...
Im not that good with programming....
I have this script attached to my enemy GameObject.. I made some modification so it could be attached to an enemy prefab so i could generate it dnamically
I have this error which i cant seem to fix it.....?????!!!!!
The script basically do these things....
-Chech if the player whithen range. -Follow the player -if whithen a range it will change the animation -and the attack script work
I keep getting this error:-
Unknown identifier: 'Player' in 5 locations..... All i wanted to do is to generate the Player data dynamically so it will be usable on any object prefab......
Please help me out.....
var MoveSpeed = 2;
var MaxDist = 25;
var MidDist = 8;
var MinDist = 3;
public var Health = 100;
var player : Transform; //current transform data of this enemy
var target : Transform; //the enemy's target
var attackTimer : float = 2;
var coolDown : float = 2;
var damage : int = 10;
function Start ()
{
attackTimer = 0;
coolDown = 2.0;
target = GameObject.FindWithTag("Player").transform;
Player = transform;//GetComponent("FirstPersonController");// gameObject.FindWithTag("Player");//.transform;
}
function Update ()
{
transform.LookAt(target);
if(Vector3.Distance(transform.position,Player.position) >= MinDist)
{
transform.position = transform.position + transform.forward*MoveSpeed*Time.deltaTime;
if(Health >=1){
animation.Play("walk");
}else if (Health <= 0){
animation.CrossFade("die");
Destroy(gameObject, 2);
}
if(Vector3.Distance(transform.position,Player.position) <= MidDist && Vector3.Distance(transform.position,Player.position) > MinDist)
{
if(Health >=1){
animation.CrossFade("charge");
}else if (Health <= 0){
animation.CrossFade("diehard");
Destroy(gameObject, 2);
}
}
if(Vector3.Distance(transform.position,Player.position) <= MaxDist && Vector3.Distance(transform.position,Player.position) < MidDist)
{
if(Health >=1){
if(attackTimer > 0){
attackTimer = attackTimer - Time.deltaTime;
}
if (attackTimer < 0){
attackTimer = 0;
}
if(attackTimer == 0){
Attack();
attackTimer = coolDown;
}
}else if (Health <= 0){
animation.CrossFade("diehard");
Destroy(gameObject, 2);
}
}
}
}
public function applyDamage(health : int){
Health = Health - health;
}
function Attack() {
var go = GameObject.Find("FirstPersonController");
go.GetComponent(playerHealth).AddjustCurrentHealth(-damage);
}
function gotHit(){
animation.CrossFade("resist");
yield WaitForSeconds(1);
}
function Test(){
Debug.Log(this.name);
}
Answer by robertbu · Feb 02, 2013 at 04:16 PM
Scripts are case sensitive. "var player" should be "var Player".