改了基类
This commit is contained in:
parent
0dc89a3bef
commit
3c1f269eb5
@ -22,19 +22,28 @@ public class Attack : MonoBehaviour
|
||||
{
|
||||
attackScope = value;
|
||||
GetComponent<CircleCollider2D>().radius = attackScope;
|
||||
//Debug.Log("¹¥»÷°ë¾¶"+GetComponent<CircleCollider2D>().radius);
|
||||
}
|
||||
}
|
||||
public async void Start()
|
||||
{
|
||||
AttackScope = attackScope;
|
||||
//AttackScope = 5;
|
||||
bulletData = new BulletData();
|
||||
bulletData.BulletScattering = 1;
|
||||
|
||||
CircleCollider2D circleCollider2D = GetComponent<CircleCollider2D>();
|
||||
|
||||
while (true) {
|
||||
CircleCollider2D circleCollider2D = GetComponent<CircleCollider2D>();
|
||||
//Debug.Log(circleCollider2D.radius);
|
||||
if (circleCollider2D)
|
||||
{
|
||||
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, circleCollider2D.radius);
|
||||
|
||||
Collider2D[] colliders = Physics2D.OverlapCircleAll(circleCollider2D.transform.position, attackScope);
|
||||
//Debug.Log(circleCollider2D.radius);
|
||||
foreach (Collider2D collider in colliders)
|
||||
{
|
||||
|
||||
Role targetRole = collider.GetComponent<Role>();
|
||||
if (targetRole && targetRole.camp != role.camp)
|
||||
{
|
||||
@ -69,16 +78,8 @@ public class Attack : MonoBehaviour
|
||||
BulletGamobj.GetComponent<Bullet>().attackObj = this ;
|
||||
BulletGamobj.transform.up = direction;
|
||||
BulletGamobj.transform.position = transform.position;
|
||||
|
||||
bulltes.Add(BulletGamobj);
|
||||
}
|
||||
Debug.Log(bulltes.Count);
|
||||
//foreach (GameObject bullet in bulltes)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public enum BulletMoveType
|
||||
PointToDirection
|
||||
}
|
||||
|
||||
|
||||
public class BulletData
|
||||
{
|
||||
[Header("子弹穿透次数")] public int NumberOfBulletPenetrations = 1;
|
||||
@ -33,9 +34,9 @@ public class BulletData
|
||||
[Header("子弹连发次数")] public int BulletBurstTimes = 1;
|
||||
[Header("子弹连发间隔")] public float BulletBurstInterval ;
|
||||
[Header("子弹穿透衰减")] public float BulletPenetrationAttenuation = 0.2f;
|
||||
[Header("子弹飞行速度")] public float BulletSpeed = 10f;
|
||||
[Header("子弹飞行速度")] public float BulletSpeed = 5f;
|
||||
[Header("子弹攻击冷却")] public float BulletAttackCooldown = 1f;
|
||||
[Header("子弹伤害")] public float attack = 0;
|
||||
[Header("子弹伤害")] public float attack = 10;
|
||||
public BulletData()
|
||||
{
|
||||
|
||||
@ -63,33 +64,40 @@ public class Bullet : MonoBehaviour
|
||||
[Header("子弹发射范围对象")] public Attack attackObj;
|
||||
[Header("子弹类型")]public BulletType myBulletType;
|
||||
[Header("攻击类型")]public BulletMoveType bulletMoveType;
|
||||
[Header("子弹数据")] public BulletData bulletData;
|
||||
[Header("子弹数据")] public BulletData bulletData =new BulletData();
|
||||
|
||||
private float timer = 0;
|
||||
private void Update()
|
||||
{
|
||||
switch (this.bulletMoveType)
|
||||
{
|
||||
//更具子弹的移动方式来移动
|
||||
case BulletMoveType.PeerToPeer:
|
||||
this.gameObject.transform.Translate(Vector3.up);
|
||||
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
|
||||
break;
|
||||
case BulletMoveType.PointToDirection:
|
||||
break;
|
||||
}
|
||||
|
||||
timer += Time.deltaTime;
|
||||
if (timer>10f)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
private async void Start()
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
Debug.Log("进入检测范围");
|
||||
Role Crole = collision.gameObject.GetComponent<Role>();
|
||||
if(Crole)
|
||||
{
|
||||
if(Crole.camp!= role.camp)
|
||||
{
|
||||
Debug.Log("进行攻击计算");
|
||||
Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role });
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
Role/Role.cs
12
Role/Role.cs
@ -34,6 +34,7 @@ public enum Camp
|
||||
[ExecuteInEditMode]
|
||||
public class Role : Fun
|
||||
{
|
||||
[Header("Id")] public int id;
|
||||
[Header("ÕóÓª")] public Camp camp ;
|
||||
[Header("ѪÁ¿")] public float hp = 100f;//ѪÁ¿
|
||||
public float Hp
|
||||
@ -93,7 +94,7 @@ public class Role : Fun
|
||||
|
||||
|
||||
|
||||
async void Start()
|
||||
public virtual async void Start()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
@ -204,14 +205,7 @@ public class Role : Fun
|
||||
|
||||
}
|
||||
|
||||
// 如果启用 MonoBehaviour,则每个固定帧速率的帧都将调用此函数
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//if (!isAnimationPlay)
|
||||
//{
|
||||
// updateAnimation();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,41 +1,66 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening; // 引入DoTween命名空间
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Collections.Generic; // 引入DoTween命名空间
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class waypoints
|
||||
{
|
||||
public List<Transform> _waypoints = new List<Transform>();
|
||||
}
|
||||
|
||||
public class SimplePathfindingDoTween : Fun
|
||||
{
|
||||
public Transform[] waypoints; // 预设的路径点
|
||||
public waypoints waypoints = new waypoints();// 预设的路径点
|
||||
public float moveSpeed = 1f; // 控制移动速度的参数(更高值表示更快的速度)
|
||||
|
||||
private int currentWaypointIndex = 0; // 当前路径点的索引
|
||||
|
||||
Vector3 Vector3 = new Vector3();
|
||||
public void MoveToNextWaypoint(GameObject gameObject)
|
||||
{
|
||||
if (currentWaypointIndex < waypoints.Length)
|
||||
{
|
||||
if (currentWaypointIndex < waypoints._waypoints.Count)
|
||||
{
|
||||
// 获取下一个路径点
|
||||
Transform targetWaypoint = waypoints[currentWaypointIndex];
|
||||
Transform targetWaypoint = waypoints._waypoints[waypoints._waypoints.Count-1];
|
||||
|
||||
// 计算路径点之间的距离
|
||||
float distance = Vector3.Distance(gameObject.transform.position, targetWaypoint.position);
|
||||
|
||||
// 根据设置的速度计算时间
|
||||
float timeToReach = distance / moveSpeed; // 根据速度控制匀速移动的时间
|
||||
|
||||
float timeToReach = distance*10 / moveSpeed; // 根据速度控制匀速移动的时间
|
||||
|
||||
// 使用DoTween的DOPath来平滑地移动到目标位置
|
||||
Vector3[] path = new Vector3[waypoints.Length - currentWaypointIndex];
|
||||
Vector3[] path = new Vector3[waypoints._waypoints.Count - currentWaypointIndex];
|
||||
for (int i = 0; i < path.Length; i++)
|
||||
{
|
||||
path[i] = waypoints[currentWaypointIndex + i].position;
|
||||
path[i] = waypoints._waypoints[currentWaypointIndex + i].position;
|
||||
}
|
||||
|
||||
// 执行路径动画,保证匀速前进
|
||||
gameObject.transform.DOPath(path, timeToReach, PathType.Linear)
|
||||
.SetEase(Ease.Linear); // 设置匀速
|
||||
.SetEase(Ease.Linear).OnUpdate(() => RotateTowardsTarget()); // 每次更新时调整旋转
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("到达终点!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RotateTowardsTarget()
|
||||
{
|
||||
Vector3 _vector3 = Vector3 - gameObject.transform.position;
|
||||
Vector3 = gameObject.transform.position;
|
||||
if (_vector3.x>0)
|
||||
{
|
||||
// 物体在目标的右边或平行,设置物体的y旋转为180°,面向左侧
|
||||
gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 物体在目标的左边,设置物体的y旋转为0°,面向右侧
|
||||
gameObject.transform.rotation = Quaternion.Euler(0, 180, 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ using UnityEngine.UI;
|
||||
|
||||
public class Base : MonoBehaviour
|
||||
{
|
||||
private List<string> LoadClassName = new List<string>() { "ImageLoader" , "Global" };//写入需要全局自动实例化的类
|
||||
private List<string> LoadClassName = new List<string>() { "ImageLoader" , "Global", "gameGlobal" };//写入需要全局自动实例化的类
|
||||
[Header("关闭窗口的按钮")] public Button retbutton;
|
||||
[Header("需要关闭的窗口")] public GameObject ClosureObj;
|
||||
public static GameObject GlobalObj;
|
||||
|
Loading…
Reference in New Issue
Block a user