private void Update() { if (playerEntity && canShoot) { float _distancePlayer = Vector3.Distance(transform.position, playerEntity.transform.position); if (_distancePlayer <= distance) { var _shotCommand = new ShotCommand(this, playerEntity.transform); _shotCommand.Execute(); transform.LookAt(playerEntity.transform); } } }
//Shot action to apply the shot command when its possible to shoot and found a closest enemy private void OnShot() { if (canShoot) { Enemy _currentTarget = SeekClosestEnemy(); if (_currentTarget) { ShotCommand _shotCommand = new ShotCommand(this, _currentTarget.transform); _shotCommand.Execute(); //look to the current enemy transform.LookAt(_currentTarget.transform); } } }