Exemple #1
0
    public virtual void Update()
    {
        timer += Time.deltaTime;
        if (timer > delay)
        {
            if (!audioSource.isPlaying)
            {
                audioSource.pitch = Random.Range(-2f, 2f);
                audioSource.Play();
                delay = Random.Range(2f, 4f);
                timer = 0;
            }
        }

        if (Vector2.Distance(transform.position, target.position) > stoppingPoint)
        {
            moveTowardTarget(target);
        }
        //TODO: Get and find the player to attack
        if (Input.GetKeyDown(KeyCode.Space))
        {
            GetDamaged(damage);
        }
        if (health <= 0)
        {
            audioSource.pitch = 1;
            if (!audioSource.isPlaying && timesPlayed < 1)
            {
                audioSource.PlayOneShot(clips[1], 0.5f);
                timesPlayed++;
            }
            dietimer += Time.deltaTime;

            if (dietimer > 0.5f)
            {
                Die();
                dietimer = 0;
            }
        }
        //TODO: When health reach 0, die
        if (Input.GetKey(KeyCode.X))
        {
            Die();
            RampageController.resetCounter();
        }

        if (isColorChanged)
        {
            resetColorTime -= Time.deltaTime;
            if (resetColorTime <= 0)
            {
                isColorChanged = false;
                resetColorTime = 0.15f;
                //Reset back to default color
                SpriteRenderer sr = GetComponent <SpriteRenderer>();
                sr.color = defaultColor;
            }
        }
    }
 public override void GetDamaged(float damage)
 {
     ChangeColor();
     health -= damage;
     if (health <= 0)
     {
         Die();
         RampageController.rampageCounter++;
         RampageController.resetCounter();
     }
 }