Inheritance: MonoBehaviour
コード例 #1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     //Si es una moneda la recoge.
     if (collision.GetComponent <CollectableScript>() != null)
     {
         CollectableScript CS = collision.GetComponent <CollectableScript>();
         if (CS.isDisabled() == false)
         {
             collision.GetComponent <CollectableScript>().Disable(false);
             GetComponentInParent <PlayerControl>().database.IncreasePoints(collision.GetComponent <CollectableScript>().value);
         }
     }
     //Si es una llave la recoge.
     else if (collision.GetComponent <KeyScript>() != null)
     {
         collision.GetComponent <KeyScript>().Pickup();
     }
 }
コード例 #2
0
    // 3 - Activate itself.
    private void Spawn()
    {
        hasSpawn = true;

        // Enable everything
        // -- Collider
        coliderComponent.enabled = true;
        // -- Moving
        moveScript.enabled = true;

        CollectableScript collectable = GetComponent <CollectableScript>();

        // -- Shooting
        if (collectable == null)
        {
            foreach (WeaponScript weapon in weapons)
            {
                weapon.enabled = true;
            }
        }
    }
コード例 #3
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        int damagePlayer = 0;

        // Ignore collision when player is invincible
        Physics2D.IgnoreCollision(collision.gameObject.GetComponent <Collider2D>(), GetComponent <Collider2D>(), isInvincible);
        if (!isInvincible)
        {
            // Collision with enemy
            EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>();
            if (enemy != null && collision.gameObject.GetComponent <BossScript>() == null)
            {
                // Kill the enemy
                HealthScript enemyHealth = enemy.GetComponent <HealthScript>();
                if (enemyHealth != null)
                {
                    damagePlayer = enemyHealth.hp / 3;
                    if (shieldLevel + 1 >= damagePlayer)
                    {
                        enemyHealth.Damage(enemyHealth.hp); // kill enemy
                    }
                }
                if (damagePlayer < 1)
                {
                    damagePlayer = 1;
                }
            }
        }

        // Is this a bonus?
        CollectableScript collectable = collision.gameObject.GetComponentInChildren <CollectableScript>();

        if (collectable != null)
        {
            // Is this a shield bonus?
            ShieldScript shield = collision.gameObject.GetComponent <ShieldScript>();
            if (shield != null)
            {
                shieldLevel     = shield.shieldLevel;
                lastShieldLevel = shieldLevel;
                updateShieldUi();
                updateLifeUi(false);
                SoundEffectsHelper.Instance.MakeShieldSound(true);
                Destroy(shield.gameObject); // Remember to always target the game object, otherwise you will just remove the script
            }
            else
            {
                SoundEffectsHelper.Instance.MakePickupSound();
            }
            // Is this a weapon bonus?
            changeWeapon(collision.gameObject);
            // Is this a bomb bonus?
            BombScript bomb = collision.gameObject.GetComponent <BombScript>();
            if (bomb != null)
            {
                if (nbBombs < MAX_BOMB)
                {
                    nbBombs++;
                    GameHelper.Instance.pickupBomb();
                }
                SoundEffectsHelper.Instance.MakePickupSound();
            }

            GameHelper.Instance.collectBonus(collectable.getId());
            Destroy(collision.gameObject); // Remember to always target the game object, otherwise you will just remove the script
        }

        // Damage the player if necessery
        if (this.takeDamage(damagePlayer))
        {
            GetComponent <HealthScript>().Damage(1);
        }
    }
コード例 #4
0
 void Awake()
 {
     collactableScript = gameObject.GetComponent <CollectableScript> ();
 }
コード例 #5
0
 public void ChangeScore(CollectableScript collectable)
 {
     Points        += collectable.GetValueScore();
     TimeLeft      += collectable.GetValueTime();
     ScoreText.text = "Score : " + Points;
 }