diff --git a/Role/Attack.cs b/Role/Attack.cs index 831ef17..e09b681 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -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(); + if (targetRole && targetRole.camp != role.camp) { role.animationHighlight = 1; @@ -143,6 +144,7 @@ public class Attack : MonoBehaviour if (bulletPrefab.GetComponent().myBulletType != BulletType.Spraying) { direction = (targetRole.transform.position - BulletStartPos.position).normalized; + Target = targetRole.gameObject; animator.SetTrigger("Attack"); } else if (bulletPrefab.GetComponent().myBulletType == BulletType.Spraying) @@ -231,6 +233,7 @@ public class Attack : MonoBehaviour BulletGamobj.GetComponent().role = role; BulletGamobj.GetComponent().attackObj = this; BulletGamobj.GetComponent().bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd); + BulletGamobj.GetComponent().Target = Target; BulletGamobj.transform.up = direction; BulletGamobj.transform.position = BulletStartPos.position; bulltes.Add(BulletGamobj); diff --git a/Role/Bullet.cs b/Role/Bullet.cs index ffe27e2..498b299 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -87,6 +87,7 @@ public class Bullet : MonoBehaviour [Header("ӵЧԤ")] public List effectPres=new List(); 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) { diff --git a/Role/Role.cs b/Role/Role.cs index db9216c..338cc68 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -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()) { - GetComponent().HarmNumber = Mathf.Round(hurt); + GetComponent().HarmNumber += Mathf.Round(hurt); } return Mathf.Round(hurt); }