void CheckSkill() { if (status.IsAttacked | status.IsAttack | status.IsDead) { return; } if (Time.time - status.LastSkillTime > status.skillRestTime | Time.time < status.skillRestTime) { skillInfo = attack.GetSkillInfo((int)status.FaceTo); status.SkillDir = status.LastDir; if (Input.GetButton("Fire2") && !status.IsSkill && status.CurBlue > status.SkillBlue) { status.IsSkill = true; status.LastSkillTime = Time.time; fireball = Instantiate(Resources.Load("player/playerSkill", typeof(playerAttack))) as playerAttack; fireball.Pstatus = status; //fireball.transform.SetParent(this.transform); //Vector2 skillPos = collider.ClosestPoint((Vector2)(target.position)); fireball.GetComponent <Transform>().position = tranform.position + skillInfo.pos; fireball.GetComponent <Transform>().rotation = skillInfo.qua; Destroy(fireball.gameObject, status.skillHoldTime); status.UpdateBlue(-status.SkillBlue); } else { status.IsSkill = false; } } //进行攻击动作 animator.SetBool("is_skill", status.IsSkill); if (status.IsSkill) { //rigidbody2d.velocity + fireball.GetComponent <Rigidbody2D>().velocity = skillInfo.speed * (Vector2)status.SkillDir; if (!audio.isPlaying) { audio.PlayOneShot((int)Time.time % 2 == 0 ? skill1 : skill2); } //Debug.LogFormat("fireball velocity {0}", fireball.GetComponent<Rigidbody2D>().velocity); } else { if (fireball) { Destroy(fireball.gameObject, 0.3f); } } }
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); }