85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Diagnostics;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using UnityEngine;
|
|||
|
using Debug = UnityEngine.Debug;
|
|||
|
|
|||
|
|
|||
|
public class Attack : MonoBehaviour
|
|||
|
{
|
|||
|
[Header("<22>ӵ<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>")] public GameObject bulletPrefab;
|
|||
|
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>")] public BulletData bulletData;
|
|||
|
[Header("<22><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>")] public Role role;
|
|||
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ")] public float attackScope;
|
|||
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public DamageType damageTyp = DamageType.noAttributeDamage;
|
|||
|
public float AttackScope
|
|||
|
{
|
|||
|
[DebuggerStepThrough]
|
|||
|
get => attackScope;
|
|||
|
[DebuggerStepThrough]
|
|||
|
set
|
|||
|
{
|
|||
|
attackScope = value;
|
|||
|
GetComponent<CircleCollider2D>().radius = attackScope;
|
|||
|
}
|
|||
|
}
|
|||
|
public async void Start()
|
|||
|
{
|
|||
|
bulletData = new BulletData();
|
|||
|
bulletData.BulletScattering = 1;
|
|||
|
while (true) {
|
|||
|
CircleCollider2D circleCollider2D = GetComponent<CircleCollider2D>();
|
|||
|
if (circleCollider2D)
|
|||
|
{
|
|||
|
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, circleCollider2D.radius);
|
|||
|
foreach (Collider2D collider in colliders)
|
|||
|
{
|
|||
|
Role targetRole = collider.GetComponent<Role>();
|
|||
|
if (targetRole && targetRole.camp != role.camp)
|
|||
|
{
|
|||
|
Debug.Log("<22><><EFBFBD><EFBFBD><E2B5BD>ײ<EFBFBD><D7B2>:" + collider.name);
|
|||
|
attack(targetRole);
|
|||
|
}
|
|||
|
}
|
|||
|
await Task.Delay((int)(1000));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
public void attack(Role targetRole)
|
|||
|
{
|
|||
|
if (bulletPrefab==null)
|
|||
|
{
|
|||
|
Debug.LogError("<22>ӵ<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>");
|
|||
|
return;
|
|||
|
}
|
|||
|
Vector2 direction = (targetRole.transform.position - transform.position).normalized;
|
|||
|
|
|||
|
List<GameObject> bulltes= new List<GameObject>();
|
|||
|
for (int i = 0; i < bulletData.BulletScattering; i++)
|
|||
|
{
|
|||
|
//<2F>ı<EFBFBD><C4B1>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>߽<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|||
|
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
|
|||
|
BulletGamobj.GetComponent<Bullet>().role = role;
|
|||
|
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)
|
|||
|
//{
|
|||
|
|
|||
|
//}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|