攻击修改
This commit is contained in:
parent
5dbbd278a6
commit
2e5e8ae1d1
@ -14,12 +14,14 @@ public class Attack : MonoBehaviour
|
||||
[Header("攻击范围")] public float attackScope;
|
||||
[Header("攻击类型")] public DamageType damageTyp = DamageType.noAttributeDamage;
|
||||
|
||||
[Header("攻击冷却时间(秒)")] public float attackCooldown = 1f; // 攻击冷却时间
|
||||
[Header("攻击持续时间")] public float attackCooldown = 1f; // 攻击冷却时间
|
||||
private float lastAttackTime = 0f; // 上次攻击的时间
|
||||
|
||||
[HideInInspector]
|
||||
public List<GameObject> bulltes = new List<GameObject>();
|
||||
|
||||
[Header("角色动画控制器")] public Animator animator;
|
||||
[Header("火焰动画控制器")] public Animator fireAni;
|
||||
public float AttackScope
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
@ -56,13 +58,31 @@ public class Attack : MonoBehaviour
|
||||
if (targetRole && targetRole.camp != role.camp)
|
||||
{
|
||||
role.animationHighlight = 1;
|
||||
attack(targetRole);
|
||||
lastAttackTime = Time.time; // 更新上次攻击时间
|
||||
if (animator!=null)
|
||||
{
|
||||
animator.SetInteger("State", 1);
|
||||
lastAttackTime = Time.time; // 更新上次攻击时间
|
||||
}
|
||||
else
|
||||
{
|
||||
attack(targetRole);
|
||||
lastAttackTime = Time.time; // 更新上次攻击时间
|
||||
}
|
||||
|
||||
break; // 只攻击一个目标
|
||||
}
|
||||
else
|
||||
{
|
||||
role.animationHighlight = 0;
|
||||
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetInteger("State", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
role.animationHighlight = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +115,7 @@ public class Attack : MonoBehaviour
|
||||
BulletGamobj.GetComponent<Bullet>().role = role;
|
||||
BulletGamobj.GetComponent<Bullet>().attackObj = this;
|
||||
// BulletGamobj.transform.up = direction;
|
||||
BulletGamobj.transform.position = transform.position;
|
||||
BulletGamobj.transform.position =new Vector2(transform.position.x+0.15f, transform.position.y+0.2f);
|
||||
bulltes.Add(BulletGamobj);
|
||||
return;
|
||||
}
|
||||
@ -114,6 +134,42 @@ public class Attack : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Fireattack()
|
||||
{
|
||||
|
||||
if (bulletPrefab == null)
|
||||
{
|
||||
Debug.LogError("子弹预制体为空");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
|
||||
{
|
||||
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
|
||||
fireAni = BulletGamobj.GetComponentInChildren<Animator>();
|
||||
BulletGamobj.GetComponent<Bullet>().role = role;
|
||||
BulletGamobj.GetComponent<Bullet>().attackObj = this;
|
||||
|
||||
// BulletGamobj.transform.up = direction;
|
||||
BulletGamobj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f);
|
||||
bulltes.Add(BulletGamobj);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void EndFire()
|
||||
{
|
||||
fireAni.SetInteger("State", 1);
|
||||
Debug.Log("停止火焰");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
bulltes.Clear();
|
||||
|
@ -125,9 +125,14 @@ public class Bullet : MonoBehaviour
|
||||
{
|
||||
if (Crole.camp != role.camp)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
|
||||
//Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
Destroy(this.gameObject);
|
||||
if (myBulletType != BulletType.Spraying)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user