Пример #1
0
 void HealthCheck()
 {
     if (hp == 0)
     {
         animator.Play("fork_death");
         bc2d.isTrigger    = true;
         rb2d.gravityScale = 0;
         rb2d.velocity     = Vector2.zero;
         if (spriteRenderer.flipX)
         {
             rb2d.AddForce((Vector2.right * 56) + (Vector2.down * 5));
         }
         else if (!spriteRenderer.flipX)
         {
             rb2d.AddForce((Vector2.left * 56) + (Vector2.down * 5));
         }
         GameObject spawn = Instantiate(weapon, transform.position, transform.rotation);
         //Animator spawnAnim = spawn.GetComponent<Animator>();
         //spawnAnim.Play("wep_drop");
         DropAnim drop = spawn.GetComponent <DropAnim>();
         drop.dropped            = true;
         hp                      = -1;
         weapon.transform.parent = null;
         Destroy(gameObject, 0.5f);
     }
 }
Пример #2
0
    void Death()
    {
        controller.attackCooldown = 3;
        animator.Play("blade_death1");
        bc2d.isTrigger    = true;
        rb2d.gravityScale = 0;
        rb2d.velocity     = Vector2.zero;
        if (spriteRenderer.flipX)
        {
            rb2d.AddForce((Vector2.right * 56) + (Vector2.down * 5));
        }
        else if (!spriteRenderer.flipX)
        {
            rb2d.AddForce((Vector2.left * 56) + (Vector2.down * 5));
        }
        GameObject spawn = Instantiate(weapon, transform.position, transform.rotation);
        //Animator spawnAnim = spawn.GetComponent<Animator>();
        //spawnAnim.Play("wep_drop");
        DropAnim drop = spawn.GetComponent <DropAnim>();

        drop.dropped            = true;
        health                  = -1;
        weapon.transform.parent = null;
        Destroy(controller.gameObject, 0.55f);
    }
Пример #3
0
    bool TakeItem(float distance, float height)
    {
        Vector2 position = transform.position;

        position.y += height;
        Vector2 item = position;

        if (spriteRenderer.flipX)
        {
            item.x -= distance;
        }
        else if (!spriteRenderer.flipX)
        {
            item.x += distance;
        }
        //Debug.DrawLine(position, item, Color.blue);
        RaycastHit2D touch = Physics2D.Linecast(position, item);

        if (touch.collider != null)
        {
            if (touch.collider.gameObject.name == "Sword" || touch.collider.gameObject.name == "Sword(Clone)")
            {
                DropAnim wep = touch.collider.gameObject.GetComponent <DropAnim>();
                if (!wep.playerGet && damageCooldown <= 0)
                {
                    if (weapon != 1)
                    {
                        //pc.weapon = 1;
                        //int prevDurability = hp.durability;
                        hp.durability = wep.durability;
                    }
                    else if (weapon == 1)
                    {
                        hp.durability += wep.durability;
                    }
                    //Destroy(col.gameObject);
                    if (hp.durability > 5)
                    {
                        hp.durability = 5;
                    }
                    wep.playerPickup = true;
                }
                return(true);
            }
            else if (touch.collider.gameObject.name == "Pitchfork" || touch.collider.gameObject.name == "Pitchfork(Clone)")
            {
                DropAnim wep = touch.collider.gameObject.GetComponent <DropAnim>();
                if (!wep.playerGet && throwCooldown <= 0 && damageCooldown <= 0)
                {
                    wep.throwable    = false;
                    wep.playerPickup = true;
                }
                return(true);
            }
        }
        return(false);
    }
Пример #4
0
 void DropWeapon()
 {
     if ((Input.GetKeyDown(KeyCode.X) || (hp.durability == 0 && attack == false)) && weapon == 1)
     {
         Vector3 wepPosition = transform.position;
         wepPosition.y += .2f;
         GameObject wep     = Instantiate(sword, wepPosition, transform.rotation);
         DropAnim   dropped = wep.GetComponent <DropAnim>();
         dropped.playerDrop = true;
         dropped.durability = hp.durability;
         weapon             = 0;
         hp.durability      = 0;
     }
 }
Пример #5
0
    void GetItem()
    {
        Collider2D [] items = Physics2D.OverlapCircleAll(transform.position, 0.1f);
        foreach (Collider2D item in items)
        {
            if (item.gameObject.name == "Sword" || item.gameObject.name == "Sword(Clone)")
            {
                DropAnim wep = item.gameObject.GetComponent <DropAnim>();
                if (!wep.playerGet && attackCooldown <= 0)
                {
                    if (weapon != 1)
                    {
                        //pc.weapon = 1;
                        //int prevDurability = hp.durability;
                        hp.durability = wep.durability;
                    }
                    else if (weapon == 1)
                    {
                        hp.durability += wep.durability;
                    }
                    if (hp.durability > 10)
                    {
                        hp.durability = 10;
                    }
                    //Destroy(col.gameObject);
                    wep.playerPickup = true;
                }
            }
            else if (item.gameObject.name == "Pitchfork" || item.gameObject.name == "Pitchfork(Clone)")
            {
                DropAnim wep = item.gameObject.GetComponent <DropAnim>();
                if (!wep.playerGet && throwCooldown <= 0 && !wep.enemyThrown)
                {
                    if (throwable < 10)
                    {
                        throwable += 3;
                    }
                    if (throwable > 10)
                    {
                        throwable = 10;
                    }
                    //Destroy(col.gameObject);
                    wep.playerPickup = true;
                }
            }
            else if (item.gameObject.tag == "Item")
            {
                if (item.gameObject.name == "Energy" || item.gameObject.name == "Energy(Clone)")
                {
                    hp.hp += 2;
                    if (hp.hp > 8)
                    {
                        hp.hp = 8;
                    }
                    hp.regainHealth = true;
                    Destroy(item.gameObject);
                }
                else if (item.gameObject.name == "Power")
                {
                    hp.power++;
                    if (hp.power > 5)
                    {
                        hp.power = 5;
                    }
                    Destroy(item.gameObject);
                }

                hp.regainHealth = false;
            }
        }
    }