Example #1
0
    private void OnTriggerStay2D(Collider2D other)
    {
        if (Input.GetKeyDown("e"))   //pickup button

        {
            weaponController old_weapon = other.gameObject.GetComponent <weaponSheath>().equiped_weapon.GetComponent <weaponController>();

            if (old_weapon != null)   //if the owner had a previous item, drop that item
            {
                old_weapon.set_drop_mode();
            }

            gameObject.transform.parent.GetComponent <weaponController>().set_pickup_mode(other.gameObject);
        }
    }
Example #2
0
    public void modHp(float deltaHp)
    {
        if (_glitchValue != null)
        {
            _glitchValue.modGlitch(deltaHp);
        }
        currentHealth += deltaHp;

        if (deltaHp < 0)   //if the entity is losing health, play damage particles
        {
            hit_particle.Play();
        }

        if (currentHealth <= 0)
        {
            //drop weapon if any

            weaponSheath sheath = gameObject.GetComponent <weaponSheath>();
            if (sheath != null)   //dont assume all entities will have a weapon sheath
            {
                weaponController old_weapon = sheath.equiped_weapon.GetComponent <weaponController>();
                if (old_weapon != null)
                {
                    old_weapon.set_drop_mode();
                }
            }

            for (int i = 0; i < Random.Range(2, 6); i++)  //drop some coins
            //ALSO RANDOMIZE POSITION
            {
                Instantiate(Resources.Load("gold_coin"), transform.position, transform.rotation);
            }

            Destroy(this.gameObject); //THIS IS VERY BAD, especially for players, fix later
        }
        else if (currentHealth > baseHealth)
        {
            currentHealth = baseHealth;
        }                                                                      //cant go over max hp
    }