Exemplo n.º 1
0
 void Start()
 {
     tranform    = GetComponent <Transform>();
     animator    = GetComponent <Animator>();
     rigidbody2d = GetComponent <Rigidbody2D>();
     audio       = GetComponent <AudioSource>();
     status      = GetComponent <playerStatus>();
     //inventoryMG = FindObjectOfType<InventoryMG>();
     weapon     = GameObject.Find("weapon");
     attack     = GetComponent <attackInfo>();
     weaponInfo = attack.GetWeaponInfo((int)status.FaceTo);
     skillInfo  = attack.GetSkillInfo((int)status.FaceTo);
     weapon.SetActive(false);
 }
Exemplo n.º 2
0
    void CheckAttack()
    {
        if (status.IsAttacked | status.IsSkill | status.IsDead)
        {
            return;
        }
        if (Time.time - status.LastAttackTime > status.attackRestTime | Time.time < status.attackRestTime)
        {
            weaponInfo = attack.GetWeaponInfo((int)status.FaceTo);
            if (Input.GetButton("Fire1") && !status.IsAttack)
            {
                status.IsAttack       = true;
                status.LastAttackTime = Time.time;
                weapon.SetActive(true);
                weapon.GetComponent <Transform>().position          = tranform.position + weaponInfo.pos;
                weapon.GetComponent <Transform>().rotation          = weaponInfo.qua;
                weapon.GetComponent <SpriteRenderer>().sortingOrder = weaponInfo.sortInLayer;
            }
            else
            {
                status.IsAttack = false;
                weapon.SetActive(false);
            }
        }


        //进行攻击动作
        animator.SetBool("is_attack", status.IsAttack);
        if (status.IsAttack)
        {
            weapon.GetComponent <Transform>().RotateAround(tranform.position + weaponInfo.rotPos, new Vector3(0, 0, 1), weaponInfo.speed);
            if (!audio.isPlaying)
            {
                audio.PlayOneShot((int)Time.time % 2 == 0 ? attack1 : attack2);
            }
        }
        else
        {
            weapon.GetComponent <Transform>().rotation = weaponInfo.qua;
        }
    }