// Update is called once per frame void Update() { if (damageScript.CurrentHealth <= 0) //if current health is zero { AudioManager.instance.PlayZombieDie(); Instantiate(chest, transform.position, Quaternion.identity); //spawn the chest gameobject GameObject death = Instantiate(deathEffect, transform.position, Quaternion.identity); //spawn death effect death.GetComponent <DeactivateObject>().BasicSettings(2f); //set death effect life span gameObject.SetActive(false); //set gameobject deactive } if (alienMode == AlienMode.idle) //if in idle mode { currentIdleTime -= Time.deltaTime; //reduce idle time if (currentIdleTime > 0) //if idle time is more than zero { anim.SetBool("Run", false); //set animation , run and attack to false anim.SetBool("Attack", false); } else if (currentIdleTime <= 0) //if idle time is less or equal to zero { if (wasRuning == false) //if alien was not running before it went to idle { wasRuning = true; //we set it to true alienMode = AlienMode.run; //set the mode to run anim.SetBool("Run", true); //set anim bool to true } else if (wasRuning == true) //if alien was running before it went to idle { wasRuning = false; //we set it to false currentCoolDown = 0; //cool down to zero currentAttackTime = attackTime; //set attack time alienMode = AlienMode.attack; //set the mode to attack } } } else if (alienMode == AlienMode.run) //if alien is in run mode { PetrolMovement(); //we call petrol movement method } else if (alienMode == AlienMode.attack) //if alien is in attack mode { currentAttackTime -= Time.deltaTime; //we reduce attack time if (currentAttackTime > 0) //if its more than zero { Attack(); //we attack anim.SetBool("Attack", true); //set animation to attack } else if (currentAttackTime <= 0) //if its less o equal to zero { ResetBeam(); //reset the beam alienMode = AlienMode.idle; //set to idle mode anim.SetBool("Attack", false); //set attack animation to false currentIdleTime = idleTime; //set idle time } } }
private float x = 0; //this is to increase the beam size with time // Use this for initialization void Start() { anim = GetComponent <Animator>(); //get the component damageScript = GetComponent <DamageScript>(); //get the component scaleX = transform.localScale.x; //set the scale currentIdleTime = idleTime; //set idle time currentAttackTime = attackTime; //set attack time alienMode = AlienMode.idle; //set mode movingRight = false; //moving right is false at start target = leftEnd.position; //at start target is left end currentCoolDown = 0; //cool down time is zero }
void PetrolMovement() { //if difference between target x and gameobject x value is less than 0.1f if (Mathf.Abs(transform.position.x - target.x) <= 0.1f) { anim.SetBool("Run", false); //set run animation to false alienMode = AlienMode.idle; //set idle mode currentAttackTime = attackTime; //set attack time movingRight = !movingRight; //change direction if (movingRight) { target = rightEnd.position; //depending on direction set next target } else if (!movingRight) { target = leftEnd.position; } scaleX = -scaleX; //inverse scale transform.localScale = new Vector3(scaleX, transform.localScale.y, transform.localScale.z); //set the scale return; //return } Move(); }