private void Health_Died(IHealth dead) { try { dead.Died -= Health_Died; var deadGameObject = AllSpawned.First(p => p.Value == dead).Key; if (DestroyIfDeath) { RemoveSpawned(deadGameObject); Destroy(deadGameObject); } else { var animMaganer = AnimationManagerBase.CreateOrGet(deadGameObject); animMaganer.SetState(AnimationState.Die); } if (dead is ILoot loot) { _player.CollectLoot(loot); } } catch (Exception e) { Console.WriteLine(e); throw; } }
void Start() { Instance = this; _rigidbody = Player.GetComponent <Rigidbody>(); _walkForce = _rigidbody.mass * 500; _jumpImpulse = _rigidbody.mass * 5f; if (PlayerAnimator != null) { AnimationManager = AnimationManagerBase.CreateOrGet(PlayerAnimator.gameObject); } }
private void Skill_OnSuccessUsed(ISkill skill, SkillContext context) { var animState = AnimationAttribute.GetAnimationState(skill); if (animState != null) { AnimationManagerBase.CreateOrGet(gameObject).SetState(animState.Value); } var audioSource = SkillBehaviour.GetAudioSource(skill); if (audioSource != null) { audioSource.Play(); } }
private void Navigate(IEnemy enemy, GameObject playerGameObject, IHealth player) { if (enemy is IHealth health) { if (health.IsDied) { _agent.isStopped = true; return; } } var animMaganer = AnimationManagerBase.CreateOrGet(gameObject); // агриться, только если не сзади if (enemy.AggressionTarget == null) { var distance = Utils.Distance(gameObject, playerGameObject); if (distance < enemy.AggressionDistance && distance > _agent.stoppingDistance) { var angle = Vector3.Angle(gameObject.transform.forward, playerGameObject.transform.forward); if (angle > 45) // конус 90 градусов сзади { enemy.AggressionTarget = player; } } } if (enemy.AggressionTarget == player) { _agent.isStopped = false; animMaganer.SetState(AnimationState.GoForward); if (PursueMode) { _agent.SetDestination(playerGameObject.transform.position); } else { var d = gameObject.transform.position - playerGameObject.transform.position; var newX = gameObject.transform.position.x + d.x / 2; var newY = gameObject.transform.position.y + d.y / 2; var newZ = gameObject.transform.position.z + d.z / 2; _agent.SetDestination(new Vector3(newX, newY, newZ)); } } else { _randomMoveLimiter.Do(() => { //if (!_agent.isStopped) // return; _agent.isStopped = false; animMaganer.SetState(AnimationState.GoForward); var randomVector = SpawnerBehaviour.GetRandomVector(new Vector3(1, 0, 1)) * (float)_rand.NextDouble() * enemy.AggressionDistance; animMaganer.SetState(AnimationState.GoForward); var target = gameObject.transform.position + randomVector; _agent.SetDestination(target); }, () => { //if (_agent.pathStatus == NavMeshPathStatus.PathComplete) if (_agent.remainingDistance <= _agent.stoppingDistance) { _agent.isStopped = true; animMaganer.SetState(AnimationState.Idle); } }); } }