Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum ENEMY_STATE
- {
- STATE_MOVE = 0,
- STATE_FOLLOW
- }
- var exitdisabled = false;
- var disableobject =false;
- // variables
- //defines current state
- var currentState :ENEMY_STATE = ENEMY_STATE.STATE_MOVE;
- //players position
- var player : Transform;
- //enemys position
- var enemy : Transform;
- //enemys gameobject
- var enemyO : GameObject;
- //enemys rotation speed
- var enemyrotationspeed :float = 10;
- //enemys speed
- var enemyspeed : float = 6;
- //enemys jump hight
- var enemyjumpspeed : float = 36;
- var disabled : boolean = false;
- //enemys target when its not player
- var target: Transform;
- var target1: Transform;
- var enemycheckpoint1:GameObject;
- var enemycheckpoint2:Transform;
- var enemycheckpoint3:GameObject;
- // min distance
- var maxdistance : float = 0.6;
- var mindistance : float = 0.3;
- var isgrounded : boolean = false;
- var fallspeed : float = 7.0;
- function Start()
- {
- target = enemycheckpoint1.transform;
- target1 = enemycheckpoint1.transform;
- enemyspeed = 0.25;
- }
- function Update()
- {
- if(disableobject == false)
- {
- if(isgrounded == true)
- {
- if(currentState == ENEMY_STATE.STATE_FOLLOW)
- {
- target1 = player.transform;
- if(Vector3.Distance(enemy.transform.position, player.transform.position) > mindistance)
- {
- enemy.transform.LookAt(Vector3(player.position.x,transform.position.y,player.position.z));
- transform.eulerAngles = Vector3(0,transform.localEulerAngles.y,0);
- if(disabled == false)
- {
- enemy.transform.position = Vector3.MoveTowards(enemy.transform.position,Vector3(player.transform.position.x,enemy.transform.position.y,player.transform.position.z),Time.deltaTime * enemyspeed); }
- }
- else
- {
- }
- }
- if(currentState == ENEMY_STATE.STATE_MOVE)
- {
- enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, Quaternion.LookRotation(target1.transform.position -enemy.transform.position), enemyrotationspeed * Time.deltaTime);
- if(disabled ==false)
- {
- enemy.transform.position = Vector3.MoveTowards(enemy.transform.position,target.transform.position,Time.deltaTime * enemyspeed);
- }
- }
- else
- {
- }
- }
- if(isgrounded ==false)
- {
- enemy.transform.position.y -= fallspeed * Time.deltaTime;
- }
- }
- }
- function OnCollisionEnter(theCollision:Collision)
- {
- if(theCollision.gameObject.tag == "ground")
- {
- isgrounded = true;
- Debug.Log("is grounded");
- }
- if(theCollision.gameObject.tag == "enemycheckpoint2")
- {
- enemy.transform.position = enemycheckpoint3.transform.position;
- enemy.transform.rotation = enemycheckpoint3.transform.rotation;
- isgrounded = false;
- exitdisabled = false;
- enemyspeed = 0.25;
- disableobject = true;
- }
- }
- function OnTriggerEnter(other:Collider)
- {
- if(other.gameObject.tag == "enemycheckpoint1")
- {
- isgrounded = true;
- exitdisabled = true;
- target1 = player.transform;
- target = enemycheckpoint2.transform;
- enemyspeed = 0.8;
- }
- if(other.gameObject.tag == "Player")
- {
- currentState = ENEMY_STATE.STATE_FOLLOW;
- }
- else
- {
- return;
- }
- }
- function OnTriggerExit(other:Collider)
- {
- if(other.gameObject.tag == "Player")
- {
- currentState = ENEMY_STATE.STATE_MOVE;
- target = enemycheckpoint1.transform;
- target1 = enemycheckpoint1.transform;
- }
- else
- {
- return;
- }
- }
- function OnCollisionExit(theCollision:Collision)
- {
- if(theCollision.gameObject.tag == "ground")
- {
- if(exitdisabled ==false)
- {
- isgrounded = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment