示例#1
0
    /// <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;
    }
示例#2
0
    /// <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);
    }
示例#3
0
 /// <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));
     }
 }
示例#4
0
 /// <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));
 }
示例#5
0
 /// <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));
     }
 }
示例#6
0
    /// <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);
     }
 }
示例#8
0
    /// <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;
    }
示例#9
0
    /// <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;
            }
        }
    }
示例#10
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Enter(GameBaseCharacter character)
 {
     character.NavMeshAgent.Resume();
     character.Animator.SetBool("ChaseState", true);
     character.Character.IsMoving = true;
 }
示例#11
0
 /// <summary>
 /// Reset the dying state.</summary>
 public override void Exit(GameBaseCharacter character)
 {
     character.enabled          = true;
     character.Animator.enabled = true;
     character.Animator.SetBool("DefeatedState", false);
 }
示例#12
0
 /// <summary>
 /// Nothing to do here.</summary>
 public override void Update(GameBaseCharacter character)
 {
 }
示例#13
0
 /// <summary>
 /// Called every frame when the State is active.</summary>
 public abstract void Update(GameBaseCharacter character);
示例#14
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Exit(GameBaseCharacter character)
 {
     character.StopCoroutine("CombatSkillCountdown");
     character.Animator.SetBool("AttackState", false);
 }
示例#15
0
 /// <summary>
 /// Called before changing to the next State.</summary>
 public virtual void Exit(GameBaseCharacter character)
 {
 }
示例#16
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Enter(GameBaseCharacter character)
 {
     character.NavMeshAgent.Stop();
     character.Animator.SetBool("AttackState", true);
 }
示例#17
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Exit(GameBaseCharacter character)
 {
     character.Animator.SetBool("ChaseState", false);
     character.Character.IsMoving = false;
 }
示例#18
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Enter(GameBaseCharacter character)
 {
     character.NavMeshAgent.Stop();
     character.Animator.SetBool("IdleState", true);
     character.Animator.SetFloat("MovementSpeed", 0);
 }
示例#19
0
 /// <summary>
 /// Called when entering the State.</summary>
 public virtual void Enter(GameBaseCharacter character)
 {
 }
示例#20
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Exit(GameBaseCharacter character)
 {
     character.NavMeshAgent.Resume();
     character.Animator.SetBool("AlertState", false);
 }
示例#21
0
 /// <summary>
 /// Stop the NavMeshAgent.</summary>
 public override void Exit(GameBaseCharacter character)
 {
     character.NavMeshAgent.Resume();
     character.Animator.SetBool("MoveState", false);
     character.Character.IsMoving = false;
 }