攻击动画
This commit is contained in:
parent
5e92a0630d
commit
d266869186
@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
@ -54,14 +55,18 @@ public class Attack : MonoBehaviour
|
||||
Role targetRole = collider.GetComponent<Role>();
|
||||
if (targetRole && targetRole.camp != role.camp)
|
||||
{
|
||||
Debug.Log("检测到碰撞器: " + collider.name);
|
||||
role.animationHighlight = 1;
|
||||
attack(targetRole);
|
||||
lastAttackTime = Time.time; // 更新上次攻击时间
|
||||
break; // 只攻击一个目标
|
||||
}
|
||||
else
|
||||
{
|
||||
role.animationHighlight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Debug.Log("=====--");
|
||||
await Task.Delay(100); // 延迟,避免过于频繁地检测
|
||||
}
|
||||
else
|
||||
@ -73,12 +78,15 @@ public class Attack : MonoBehaviour
|
||||
|
||||
public void attack(Role targetRole)
|
||||
{
|
||||
|
||||
if (bulletPrefab == null)
|
||||
{
|
||||
Debug.LogError("子弹预制体为空");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2 direction = (targetRole.transform.position - transform.position).normalized;
|
||||
|
||||
if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
|
||||
@ -103,7 +111,6 @@ public class Attack : MonoBehaviour
|
||||
BulletGamobj.transform.position = transform.position;
|
||||
bulltes.Add(BulletGamobj);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class Bullet : MonoBehaviour
|
||||
if (myBulletType!=BulletType.Spraying)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
//Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
@ -119,14 +119,14 @@ public class Bullet : MonoBehaviour
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
Debug.Log("进入检测范围");
|
||||
//Debug.Log("进入检测范围");
|
||||
Role Crole = collision.gameObject.GetComponent<Role>();
|
||||
if (Crole)
|
||||
{
|
||||
if (Crole.camp != role.camp)
|
||||
{
|
||||
attackObj.bulltes.Remove(this.gameObject);
|
||||
Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
//Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
17
Role/Role.cs
17
Role/Role.cs
@ -43,6 +43,7 @@ public class Role : Fun
|
||||
[Header("hp填充")] public Image Hpfiil;
|
||||
[Header("扣血填充")] public GameObject HpTextPrefab;
|
||||
[Header("自己的画布")]public Canvas _Canvas;
|
||||
|
||||
public float Hp
|
||||
{
|
||||
get => hp;
|
||||
@ -123,14 +124,10 @@ public class Role : Fun
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (attackClass)
|
||||
{
|
||||
attackClass.role = this;
|
||||
}
|
||||
|
||||
UpdateBuff();
|
||||
//Navigation.MoveToNextWaypoint(gameObject);
|
||||
}
|
||||
@ -167,7 +164,6 @@ public class Role : Fun
|
||||
return;
|
||||
};
|
||||
OnAnimationStart?.Invoke(animationHighlight);
|
||||
CurrentIndex = 0;
|
||||
var lsanimationHighlight = animationHighlight;
|
||||
foreach (Sprite sprite in LightSprite)
|
||||
{
|
||||
@ -187,8 +183,6 @@ public class Role : Fun
|
||||
OnAnimationIng?.Invoke(animationHighlight);
|
||||
await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval);
|
||||
}
|
||||
|
||||
CurrentIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -200,6 +194,7 @@ public class Role : Fun
|
||||
|
||||
if (lsanimationHighlight == dieIndex)
|
||||
{
|
||||
|
||||
SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
|
||||
ResetAllStatus();
|
||||
}
|
||||
@ -294,13 +289,7 @@ public class Role : Fun
|
||||
mycollider.enabled = true; // 启用碰撞体
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 如果有其他需要重置的状态,可以在这里添加
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user