Tuesday, December 14, 2010

Week 11: Programming


Beginning Sedja AI Script:

var horous: GameObject;
var enemyState = "String";
var health=100;
var attackState="String";

function Start(){
enemyState="chasemode";
attackState="weak";
}
function Update () {


var dist =Vector3.Distance(horous.transform.position, transform.position);
if(dist>=5){
enemyState="chasemode";

}
if(enemyState=="chasemode"){
enemychase();
}
if(enemyState=="attackmode"){
attackmode();
}
if(health<=0){
Destroy(gameObject);
}

}
function enemychase(){
transform.LookAt(horous.transform);
var dist =Vector3.Distance(horous.transform.position, transform.position);

if(dist<=2.3){
enemyState="attackmode";
animation.Play ("runoutro");

}
else{
rigidbody.transform.Translate(5*Vector3.forward * Time.deltaTime);
animation.Play ("run");
}
}
function attackmode(){
if(health<=0){
animation.Play ("attack2");
}
else{
animation.Play ("attack");
}
}


function OnGUI () {

GUI.Label(Rect(Screen.width - 120, 10, 200, 50),"Enemy Health: " + health);

}
function OnTriggerExit(other : Collider){
if (other.gameObject.tag == "player_weapon") {
health-=10;
}
}



No comments:

Post a Comment