Example #1
0
 void Update()
 {
     // IF this character is able to move.
     if (characterManager.canMove)
     {
         // Get the list of all the characters.
         listCharacter = Character_Helper.GetCharactersByType(listCharacter, TypeToFollow);
         // IF the List of CharacterTypes is greater than 0.
         if (listCharacter.Count > 0)
         {
             // Get the closest GameObject with the CharacterType chosen and save it to _character.
             GameObject _character = Character_Helper.GetClosestCharacterType(characterManager.characterEntity.transform, TypeToFollow, AggroDistance);
             // IF the closest gameobject is not null AND IF both GameObjects distance apart from each other is greater than the Gap Distance.
             if (_character != null && Vector3.Distance(_transform.position, _character.transform.position) >= gapDistance)
             {
                 // Move the actual character of this gameobject closer to _character gameobject.
                 characterManager.characterEntity.transform.position =
                     Vector2.MoveTowards(characterManager.characterEntity.transform.position, _character.GetComponent <Character> ().characterEntity.transform.position, Time.deltaTime * charStats.CurrentMoveSpeed);
             }
         }
     }
 }