This commit is contained in:
GL 2024-12-27 18:13:16 +08:00
parent cdcf8585ab
commit ec0eb5a298
3 changed files with 18 additions and 4 deletions

View File

@ -37,7 +37,7 @@ public class Attack : MonoBehaviour
[Header("矩形攻击碰撞体")] public BoxCollider2D attackColliderBox;
[Header("攻击范围图片")] public SpriteRenderer attackRangeSprite;
[Header("攻击持续时间")] public float AttackStayTime;//
[Header("攻击目标")] public GameObject Target;
public bool isAttack = true;
public bool flag = false;
[HideInInspector] public float timer = 0;
@ -135,6 +135,7 @@ public class Attack : MonoBehaviour
foreach (Collider2D collider in colliders)
{
Role targetRole = collider.GetComponent<Role>();
if (targetRole && targetRole.camp != role.camp)
{
role.animationHighlight = 1;
@ -143,6 +144,7 @@ public class Attack : MonoBehaviour
if (bulletPrefab.GetComponent<Bullet>().myBulletType != BulletType.Spraying)
{
direction = (targetRole.transform.position - BulletStartPos.position).normalized;
Target = targetRole.gameObject;
animator.SetTrigger("Attack");
}
else if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
@ -231,6 +233,7 @@ public class Attack : MonoBehaviour
BulletGamobj.GetComponent<Bullet>().role = role;
BulletGamobj.GetComponent<Bullet>().attackObj = this;
BulletGamobj.GetComponent<Bullet>().bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd);
BulletGamobj.GetComponent<Bullet>().Target = Target;
BulletGamobj.transform.up = direction;
BulletGamobj.transform.position = BulletStartPos.position;
bulltes.Add(BulletGamobj);

View File

@ -87,6 +87,7 @@ public class Bullet : MonoBehaviour
[Header("子弹特效预制体")] public List<GameObject> effectPres=new List<GameObject>();
private float timer = 0;
[Header("子弹攻击数量")] public int NumberOfBulletAttacks = 1;
[Header("¹¥»÷Ä¿±ê")] public GameObject Target;
private void Update()
{
switch (this.bulletMoveType)
@ -95,7 +96,17 @@ public class Bullet : MonoBehaviour
case BulletMoveType.PeerToPeer:
if (IsMove)
{
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
if (Target != null&&Target.activeSelf==true)
{
this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, Target.transform.position, Time.deltaTime * bulletData.BulletSpeed);
}
else
{
this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed);
}
timer += Time.deltaTime;
if (timer > BulletDeadTimer)
{

View File

@ -314,7 +314,7 @@ public class Role : Fun
{
animationHighlight = dieIndex;
Navigation.PauseAnimation();
mycollider.enabled = false;
//mycollider.enabled = false;
Debug.Log("die");
}
@ -539,7 +539,7 @@ public class Role : Fun
if (GetComponent<enemy>())
{
GetComponent<enemy>().HarmNumber = Mathf.Round(hurt);
GetComponent<enemy>().HarmNumber += Mathf.Round(hurt);
}
return Mathf.Round(hurt);
}