/// <summary> /// Bring the movement speed down to a still stand.</summary> public override void Update(GameBaseCharacter character) { if (character.NavMeshAgent.pathPending) { return; } if (character.Animator.GetFloat("MovementSpeed") < 1) { character.Animator.SetFloat("MovementSpeed", Math.Min(1, character.Animator.GetFloat("MovementSpeed") + Time.deltaTime * 6)); } var enemyPos = new Vector3(character.Character.TargetedEnemy.Position.X, 0, character.Character.TargetedEnemy.Position.Y); var charPos = new Vector3(character.Character.Position.X, 0, character.Character.Position.Y); var direction = (enemyPos - charPos).normalized * (float)Math.Sqrt(character.Character.AttackRange); var destination = new Vector3(character.Character.TargetedEnemy.Position.X, 0, character.Character.TargetedEnemy.Position.Y) + direction; character.NavMeshAgent.destination = destination; }
/// <summary> /// Look at the TargetedEnemy.</summary> public override void Update(GameBaseCharacter character) { var target = new Vector3(character.Character.TargetedEnemy.Position.X, 0, character.Character.TargetedEnemy.Position.Y); character.transform.LookAt(target); }
/// <summary> /// Bring the movement speed down to a still stand.</summary> public override void Update(GameBaseCharacter character) { if (character.Character.Enemies.Count > 0) { character.NavMeshAgent.SetDestination(new Vector3(character.Character.Enemies[0].Position.X, 0, character.Character.Enemies[0].Position.Y)); } }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Enter(GameBaseCharacter character) { character.Animator.SetBool("DefeatedState", true); character.NavMeshAgent.enabled = false; character.gameObject.tag = "Untagged"; character.Collider.enabled = false; character.StartCoroutine(DefeatAnimation(character)); }
/// <summary> /// Bring the movement speed down to a still stand.</summary> public override void Update(GameBaseCharacter character) { if (character.Animator.GetFloat("MovementSpeed") > 0) { character.Animator.SetFloat("MovementSpeed", Math.Max(0, character.Animator.GetFloat("MovementSpeed") - Time.deltaTime * 6)); } }
/// <summary> /// Instantiate loot.</summary> public void DropLoot(GameBaseCharacter character) { var loot = (Loot)ScriptableObject.Instantiate(character.LootPrefab, new Vector3(character.Character.Position.X, 0, character.Character.Position.Y), character.transform.rotation); loot.Inventory = character.Character.Inventory; character.transform.SetParent(loot.transform); }
/// <summary> /// Change to attack or chase State when an enemy was hit with /// user input. /// Also set the enemy as the first enemy in the list of enemies.</summary> private void HitEnemy(RaycastHit hit) { GameBaseCharacter enemy = hit.collider.gameObject.GetComponent<GameBaseCharacter>(); GamePlayer.Instance.Character.AddEnemy(enemy.Character, 0); GamePlayer.Instance.Character.TargetedEnemy = enemy.Character; // Attack if (GamePlayer.Instance.Character.CanAttack()) { GamePlayer.Instance.Character.Attack(enemy.Character); } }
/// <summary> /// Play the dying animation and remove the Character after a time.</summary> public IEnumerator DefeatAnimation(GameBaseCharacter character) { float endTime = Time.time + 3; character.Animator.SetFloat("DefeatAnimation", UnityEngine.Random.Range(0, 2)); while (Time.time < endTime) { yield return(null); } DropLoot(character); character.Animator.enabled = false; character.enabled = false; }
/// <summary> /// Bring the movement speed down to a still stand.</summary> public override void Update(GameBaseCharacter character) { if (character.NavMeshAgent.pathPending) { return; } if (character.Animator.GetFloat("MovementSpeed") < character.Character.Stats.MovementSpeed.Value) { character.Animator.SetFloat("MovementSpeed", Math.Min(character.Character.Stats.MovementSpeed.Value, character.Animator.GetFloat("MovementSpeed") + Time.deltaTime)); } if (character.NavMeshAgent.remainingDistance <= character.NavMeshAgent.stoppingDistance) { if (!character.NavMeshAgent.hasPath || Mathf.Abs(character.NavMeshAgent.velocity.sqrMagnitude) < float.Epsilon) { character.Character.IsMoving = false; } } }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Enter(GameBaseCharacter character) { character.NavMeshAgent.Resume(); character.Animator.SetBool("ChaseState", true); character.Character.IsMoving = true; }
/// <summary> /// Reset the dying state.</summary> public override void Exit(GameBaseCharacter character) { character.enabled = true; character.Animator.enabled = true; character.Animator.SetBool("DefeatedState", false); }
/// <summary> /// Nothing to do here.</summary> public override void Update(GameBaseCharacter character) { }
/// <summary> /// Called every frame when the State is active.</summary> public abstract void Update(GameBaseCharacter character);
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Exit(GameBaseCharacter character) { character.StopCoroutine("CombatSkillCountdown"); character.Animator.SetBool("AttackState", false); }
/// <summary> /// Called before changing to the next State.</summary> public virtual void Exit(GameBaseCharacter character) { }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Enter(GameBaseCharacter character) { character.NavMeshAgent.Stop(); character.Animator.SetBool("AttackState", true); }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Exit(GameBaseCharacter character) { character.Animator.SetBool("ChaseState", false); character.Character.IsMoving = false; }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Enter(GameBaseCharacter character) { character.NavMeshAgent.Stop(); character.Animator.SetBool("IdleState", true); character.Animator.SetFloat("MovementSpeed", 0); }
/// <summary> /// Called when entering the State.</summary> public virtual void Enter(GameBaseCharacter character) { }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Exit(GameBaseCharacter character) { character.NavMeshAgent.Resume(); character.Animator.SetBool("AlertState", false); }
/// <summary> /// Stop the NavMeshAgent.</summary> public override void Exit(GameBaseCharacter character) { character.NavMeshAgent.Resume(); character.Animator.SetBool("MoveState", false); character.Character.IsMoving = false; }