コード例 #1
0
        void Update()
        {
            // IF this character is able to move.

            if (character.CanMove)
            {
                // Get the list of all the characters.
                listCharacter = Character_Manager.GetCharactersByType(listCharacter, TypeToFollow);
                // IF the List of CharacterTypes is greater than 0.
                if (listCharacter.Count > 0)
                {
                    // Create a GameObject variable.
                    GameObject _character = null;
                    // Get the closest GameObject with the CharacterType chosen and save it to _character.
                    _character = Character_Manager.GetClosestCharacterType(character.transform, TypeToFollow, _character, AggroDistance);
                    // IF the closest gameobject is not null.
                    if (_character != null)
                    {
                        // Move the actual character of this gameobject closer to _character gameobject.
                        character.characterEntity.transform.position =
                            Vector2.MoveTowards(transform.position, _character.GetComponent <Character> ().characterEntity.transform.position, Time.deltaTime * Speed);
                    }
                }
            }
        }
コード例 #2
0
        void Wander()
        {
            // Create a GameObject variable.
            GameObject _character = null;

            // Get the closest GameObject with the CharacterType chosen and save it to _character.
            _character = Character_Manager.GetClosestCharacterType(character.transform, TypeToFollow, _character, AggroDistance);
            // IF the closest gameobject is not null.
            if (_character != null)
            {
                //TODO WHY DO I GIVE UP ON HIM AFTER HE PICKS UP THE BALL?
                float distance = (transform.position - _character.GetComponent <Character>().characterEntity.transform.position).magnitude;
                if (distance > ComfortZoneEnd)
                {
                    // Move the actual character of this gameobject closer to _character gameobject.
                    character.characterEntity.transform.position =
                        Vector2.MoveTowards(transform.position, _character.GetComponent <Character>().characterEntity.transform.position, Time.deltaTime * True_Speed);
                }
                else if (distance < ComfortZoneStart)
                {
                    // Move the actual character of this gameobject further from _character gameobject.
                    character.characterEntity.transform.position =
                        Vector2.MoveTowards(transform.position, _character.GetComponent <Character>().characterEntity.transform.position, Time.deltaTime * True_Speed * -1);
                }
            }
        }