我们的新敌人 sprite。
private enum EnemyType
{
Default,
Zigzag,
Aggressive,
Smart,
Evasive
}
[SerializeField] private GameObject _playerLaserContainer;
public GameObject PlayerLaserContainer => _playerLaserContainer;
private float _avoidDistance = 3.0f;
private void CalculateMovement()
{
switch (_type)
{
//other cases
case EnemyType.Evasive:
Vector3 _enemyMoveDirection = Vector3.down;
bool _foundLaser = false;
LaserBehaviour[] _trackLasers = SpawnManager.Instance.PlayerLaserContainer.GetComponentsInChildren<LaserBehaviour>();
for (int i = 0; i < _trackLasers.Length; i++)
{
if (_trackLasers[i] != null && _trackLasers[i].gameObject != null && _trackLasers[i].gameObject.activeSelf)
{
Vector3 _directionToLaser = _trackLasers[i].transform.position - transform.position;
if (Mathf.Abs(_directionToLaser.magnitude) < _avoidDistance)
{
_enemyMoveDirection = -_directionToLaser;
_foundLaser = true;
}
}
}
if(_foundLaser)
transform.Translate(_enemySpeed / 2f * Time.deltaTime * _enemyMoveDirection);
else
transform.Translate(_enemySpeed * Time.deltaTime * _enemyMoveDirection);
break;
default:
break;
}
TeleportNewPosition();
}
我们的敌人试图躲避我们的激光。