示例#1
0
    public void takeDamage(float n)
    {
        if (Time.time - lastDamaged < damageDelay)
        {
            return;
        }
        health     -= n;
        lastDamaged = Time.time;
        ShowDamage();
        if (health <= 0)
        {
            //Destroy(this.gameObject);
            Main.S.EnemyDestroyed(this);
            LimitedLifetime l = gameObject.AddComponent <LimitedLifetime>();
            l.framesToLive = 30;

            if (audioSource != null)
            {
                audioSource.PlayOneShot(dieSound);
            }
        }
        if (audioSource != null)
        {
            audioSource.PlayOneShot(hitSound);
        }
    }
示例#2
0
    void OnCollisionEnter(Collision coll)
    {
        // We only care if we collide with a player.
        // Gameobjects may be given a tag via a slot at the top of the inspector.
        if (coll.gameObject.tag == "Player")
        {
            // Increment the globally accessible rupee count.
            Player.rupeeCount++;

            // Refresh the display to reflect this change.
            Hud.RefreshDisplay();

            // Stop the rupee from moving.
            GetComponent <Rigidbody>().velocity = Vector3.zero;

            // Destroy the Rupee's collider, so it can no longer collide.
            // Without this, one rupee may collide with a player many times,
            // resulting in an incorrect incrementation of the player's rupee count.
            Destroy(GetComponent <Collider>());

            // Give the rupee a Limited Lifetime component so it disappears with style.
            LimitedLifetime l = gameObject.AddComponent <LimitedLifetime>();

            // It is difficult to initialize components with parameters
            // (in constrast with traditional object constructors, which allow parameters easily)
            // We edit the component's "framesToLive" property to make the rupee disappear quickly.
            l.framesToLive = 30;
        }
    }
示例#3
0
 public void Activate()
 {
     if (!life)
     {
         life = gameObject.AddComponent <LimitedLifetime>();
     }
     life.Initiate(time);
 }
示例#4
0
    void OnCollisionEnter(Collision coll)
    {
        // We only care about collisions with bubble projectiles.
        // Tags may be set for gameobjects near the top of the inspector.
        if (coll.gameObject.tag != "Bubble")
        {
            return;
        }

        // If this enemy is invincible and we've collided with a bubble, destroy the bubble.
        if (currentState == EntityState.INVINCIBLE && coll.gameObject.tag == "Bubble")
        {
            Destroy(coll.gameObject);
            return;
        }

        if (currentState == EntityState.NORMAL)
        {
            // Spew Rupees from the enemy.
            for (int i = 0; i < 5; i++)
            {
                Vector3 newVelocity = UnityEngine.Random.onUnitSphere * 10;
                newVelocity = new Vector3(newVelocity.x, newVelocity.y, 0);
                GameObject newRupee = Instantiate(rupeePrefab, transform.position, Quaternion.identity) as GameObject;
                newRupee.GetComponent <Rigidbody>().velocity = newVelocity;
            }

            // The enemy has been hit by a bubble, so stun the enemy.
            Element.disruptElement(elementQueue, new ElementStunned(this, 60, true));

            // Add a Spin Attack element, so the enemy will attack when the stunned element finishes.
            Element.addElement(elementQueue, new ElementSpinAttack(this, Player.instance, 0.05f));

            health--;
            if (health <= 0)
            {
                // The enemy has been killed. Give it a death animation via the
                // Limited Lifetime component.
                LimitedLifetime l = gameObject.AddComponent <LimitedLifetime>();
                l.framesToLive = 30;
            }
        }
    }