飘血
This commit is contained in:
parent
f26a7c194d
commit
5e92a0630d
133
Role/Role.cs
133
Role/Role.cs
@ -37,12 +37,34 @@ public class Role : Fun
|
|||||||
[Header("Id")] public int id;
|
[Header("Id")] public int id;
|
||||||
[Header("阵营")] public Camp camp ;
|
[Header("阵营")] public Camp camp ;
|
||||||
[Header("血量")] public float hp = 100f;//血量
|
[Header("血量")] public float hp = 100f;//血量
|
||||||
|
private float maxHp;
|
||||||
|
[Header(("死亡动画编号"))] public int dieIndex=-1;
|
||||||
|
|
||||||
|
[Header("hp填充")] public Image Hpfiil;
|
||||||
|
[Header("扣血填充")] public GameObject HpTextPrefab;
|
||||||
|
[Header("自己的画布")]public Canvas _Canvas;
|
||||||
public float Hp
|
public float Hp
|
||||||
{
|
{
|
||||||
get => hp;
|
get => hp;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
float temp = hp;
|
||||||
hp = value;
|
hp = value;
|
||||||
|
|
||||||
|
if (Hpfiil!=null)
|
||||||
|
{
|
||||||
|
Hpfiil.fillAmount = hp / maxHp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HpTextPrefab != null&& hp<maxHp)
|
||||||
|
{
|
||||||
|
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
|
||||||
|
|
||||||
|
go.GetComponent<Text>().text= (temp - hp).ToString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (hp <= 0)
|
if (hp <= 0)
|
||||||
{
|
{
|
||||||
die();
|
die();
|
||||||
@ -90,14 +112,20 @@ public class Role : Fun
|
|||||||
public event AnimationItem OnAnimationEnd;
|
public event AnimationItem OnAnimationEnd;
|
||||||
[Header("动画是否正常播放")] public bool isAnimationPlay = false;//动画是否正常播放
|
[Header("动画是否正常播放")] public bool isAnimationPlay = false;//动画是否正常播放
|
||||||
[Header("碰撞体")]public CircleCollider2D mycollider;
|
[Header("碰撞体")]public CircleCollider2D mycollider;
|
||||||
[Header("¹¥»÷½Å±¾")] public Attack attackClass;
|
[Header("攻击脚本")] public Attack attackClass;
|
||||||
|
[Header("当前播放图片序列")] public int CurrentIndex;
|
||||||
|
|
||||||
|
|
||||||
public virtual async void Start()
|
public virtual async void Start()
|
||||||
{
|
{
|
||||||
|
maxHp = hp;
|
||||||
|
|
||||||
|
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (attackClass)
|
if (attackClass)
|
||||||
{
|
{
|
||||||
attackClass.role = this;
|
attackClass.role = this;
|
||||||
@ -139,35 +167,55 @@ public class Role : Fun
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
OnAnimationStart?.Invoke(animationHighlight);
|
OnAnimationStart?.Invoke(animationHighlight);
|
||||||
|
CurrentIndex = 0;
|
||||||
|
var lsanimationHighlight = animationHighlight;
|
||||||
foreach (Sprite sprite in LightSprite)
|
foreach (Sprite sprite in LightSprite)
|
||||||
{
|
{
|
||||||
if (image != null)
|
if (lsanimationHighlight == animationHighlight)
|
||||||
{
|
{
|
||||||
image.sprite = sprite;
|
if (image != null)
|
||||||
|
{
|
||||||
|
image.sprite = sprite;
|
||||||
|
}
|
||||||
|
else if (spriteRenderer != null)
|
||||||
|
{
|
||||||
|
spriteRenderer.sprite = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animationHighlight >= 0 && animationHighlight < AnimationTree.Count)
|
||||||
|
{
|
||||||
|
OnAnimationIng?.Invoke(animationHighlight);
|
||||||
|
await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentIndex++;
|
||||||
}
|
}
|
||||||
else if (spriteRenderer != null)
|
else
|
||||||
{
|
{
|
||||||
spriteRenderer.sprite = sprite;
|
break;
|
||||||
}
|
}
|
||||||
if (animationHighlight >= 0 && animationHighlight < AnimationTree.Count)
|
|
||||||
{
|
|
||||||
OnAnimationIng?.Invoke(animationHighlight);
|
|
||||||
await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
OnAnimationEnd?.Invoke(animationHighlight);
|
|
||||||
|
OnAnimationEnd?.Invoke(lsanimationHighlight);
|
||||||
|
|
||||||
|
if (lsanimationHighlight == dieIndex)
|
||||||
|
{
|
||||||
|
SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中
|
||||||
|
ResetAllStatus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 角色死亡
|
/// 角色死亡
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void die()
|
public virtual void die()
|
||||||
{
|
{
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
{
|
{
|
||||||
Destroy(gameObject);
|
animationHighlight = dieIndex;
|
||||||
|
Navigation.PauseAnimation();
|
||||||
|
Debug.Log("die");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -205,9 +253,54 @@ public class Role : Fun
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置角色所有状态
|
||||||
|
/// </summary>
|
||||||
|
public void ResetAllStatus()
|
||||||
|
{
|
||||||
|
// 重置血量
|
||||||
|
Hp = 100f;
|
||||||
|
|
||||||
|
// 重置攻击力
|
||||||
|
Attack = 10f;
|
||||||
|
|
||||||
|
// 重置护甲
|
||||||
|
physicalArmor = 10;
|
||||||
|
magicArmor = 5;
|
||||||
|
|
||||||
|
// 重置等级
|
||||||
|
Level = 1;
|
||||||
|
|
||||||
|
// 重置金币
|
||||||
|
Gold = 10f;
|
||||||
|
|
||||||
|
// 清空 Buff 列表
|
||||||
|
buffList.Clear();
|
||||||
|
|
||||||
|
// 如果有导航组件,停止当前的导航行为
|
||||||
|
if (Navigation != null)
|
||||||
|
{
|
||||||
|
//Navigation.Stop(); // 假设你有 Stop 方法来停止导航
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置角色动画
|
||||||
|
animationHighlight = 0;
|
||||||
|
isAnimationPlay = false;
|
||||||
|
|
||||||
|
// 重置碰撞体(根据需求是否需要调整)
|
||||||
|
if (mycollider != null)
|
||||||
|
{
|
||||||
|
mycollider.enabled = true; // 启用碰撞体
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 如果有其他需要重置的状态,可以在这里添加
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ public class SimplePathfindingDoTween : Fun
|
|||||||
|
|
||||||
private int currentWaypointIndex = 0; // 当前路径点的索引
|
private int currentWaypointIndex = 0; // 当前路径点的索引
|
||||||
Vector3 Vector3 = new Vector3();
|
Vector3 Vector3 = new Vector3();
|
||||||
|
|
||||||
|
[Header("旋转的动画")]public GameObject obj;
|
||||||
public void MoveToNextWaypoint(GameObject gameObject)
|
public void MoveToNextWaypoint(GameObject gameObject)
|
||||||
{
|
{
|
||||||
if (currentWaypointIndex < waypoints._waypoints.Count)
|
if (currentWaypointIndex < waypoints._waypoints.Count)
|
||||||
@ -47,7 +49,11 @@ public class SimplePathfindingDoTween : Fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public void PauseAnimation()
|
||||||
|
{
|
||||||
|
// 暂停动画
|
||||||
|
transform.DOPause();
|
||||||
|
}
|
||||||
void RotateTowardsTarget()
|
void RotateTowardsTarget()
|
||||||
{
|
{
|
||||||
Vector3 _vector3 = Vector3 - gameObject.transform.position;
|
Vector3 _vector3 = Vector3 - gameObject.transform.position;
|
||||||
@ -55,12 +61,12 @@ public class SimplePathfindingDoTween : Fun
|
|||||||
if (_vector3.x>0)
|
if (_vector3.x>0)
|
||||||
{
|
{
|
||||||
// 物体在目标的右边或平行,设置物体的y旋转为180°,面向左侧
|
// 物体在目标的右边或平行,设置物体的y旋转为180°,面向左侧
|
||||||
gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
|
obj.transform.rotation = Quaternion.Euler(0, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 物体在目标的左边,设置物体的y旋转为0°,面向右侧
|
// 物体在目标的左边,设置物体的y旋转为0°,面向右侧
|
||||||
gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
|
obj.transform.rotation = Quaternion.Euler(0, 180, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user