Trent Butler's Documentation - TrentButler/Unity-ProductionTeams GitHub Wiki

This documentation will briefly cover the following behaviors and give a few code examples:

~ GameManager
~ HealthPackBehaviour
~ PayloadBehaviour
~ PayloadPusherBehaviour
~ PlayerBehaviour
~ TowerBehaviour

GameManager

void PauseGame() Gathers all moving gameobjects and locks their movement
void ResumeGame() Gathers all moving gameobjects and unlocks their movement
void MainMenu() Changes the scene to the ‘main menu’ scene
void QuitGame() Closes the application
void NextRound() Increments various member variables, Gathers all ‘enemies’ and deletes them, reset the player and payload to original spawning point, instantiates an healthpack
void Populate() Initializes various enemies with respect to an timer
List<GameObject> Gather() Finds all ‘enemy’ gameobjects and returns them in a list
bool GameLoop() Checks for user input, invokes ‘NextRound()’ when an timer reaches three minutes
void UpdateEnemies() Iterates over an list, removes an object if that object is null
string _roundTime() Returns an string representation of the current game time
void UpdateUI() Updates the user interface with the current games information
void Start() Initializes the ‘game manager’ object’s member variables
void Update() Checks if the game needs to go to the next round, end, or if a scene change is needed

Code Example:

private void PauseGame()
    {
        Time.timeScale = 0;
        _isPaused = true;

        _buttonpanel.SetActive(true);

        var _player = GameObject.FindGameObjectWithTag("Player");
        var _payload = GameObject.FindGameObjectWithTag("Payload");
        var _enemybullets = GameObject.FindGameObjectsWithTag("JunkBullet");
        var _playerbullets = GameObject.FindGameObjectsWithTag("PlayerBullet");

        var enemies = Gather();        
        var enemyBullets = _enemybullets.ToList<GameObject>();
        var playerBullets = _playerbullets.ToList<GameObject>();

        enemies.ForEach(enemy => { enemy.GetComponent<Rigidbody>().isKinematic = true; });
        enemyBullets.ForEach(bullet => { bullet.GetComponent<Rigidbody>().isKinematic = true; });
        playerBullets.ForEach(bullet => { bullet.GetComponent<Rigidbody>().isKinematic = true; });

        _player.GetComponent<Rigidbody>().isKinematic = true;
        _payload.GetComponent<Rigidbody>().isKinematic = true;
    }

HealthPackBehaviour

void OnTriggerEnter(Collider other) Checks the tag of ‘other’, if the tag is “Player” increment the player’s health by a specified value, then invoke the ‘Destroy()’ method on the attached gameobject

Code Example:

private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Player")
        {
            if(RestoreValue <= 0.0f)
            {
                RestoreValue = 25.0f;
            }
            other.GetComponent<PlayerBehaviour>()._player.Health += RestoreValue;
            Destroy(gameObject);
        }
    }

PayloadBehaviour

void Start() Initializes various member variables, invokes the attached NavMeshAgent’s method ‘SetDestination()’ with a specified target
void FixedUpdate() Updates the attached NavMeshAgent’s target every frame, assigns NavMeshAgent’s member variable ‘acceleration’ with the member variable ‘PusherEffort’
void OnTriggerEnter(Collider other) Checks the tag of ‘other’, if the tag is “PayloadPusher” increment the member variable ‘PusherEffort’ by a specified value, if the tag is “Tower” changes the scene to the game over scene, if the tag is “Player” the attached gameobject’s position is assigned its original position
void OnTriggerExit(Collider other) Checks the tag of ‘other’, if the tag is “PayloadPusher” decrement the member variable ‘PusherEffort’ by a specified value

Code Example:

private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "PayloadPusher")
        {
            PusherEffort += other.GetComponent<PayloadPusherBehaviour>().Pusher.Damage;
        }

        if (other.tag == "Tower")
        {
            SceneManager.LoadScene("4.gameover");
        }

        if(other.tag == "Player")
        {
            transform.position = PayloadSpawn.position;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "PayloadPusher")
        {
            PusherEffort -= other.GetComponent<PayloadPusherBehaviour>().Pusher.Damage;
        }
    }

PayloadPusherBehaviour

bool Push() Returns true if ‘remainingDistance’ is less than ‘stoppingDistance’, if not return false
void Dead() Invokes the ‘Destroy()’ method on the attached gameobject
void Start() Initializes various member variables, invokes the ‘SetDestination()’ method on a specified target
void Update() Invokes the ‘Dead()’ method if the member variable ‘Pusher.Health’ is less than zero
void FixedUpdate() Updates the attached NavMeshAgent’s target every frame

Code Example:

private void FixedUpdate()
    {
        _target = GameObject.FindGameObjectWithTag("Payload").GetComponent<PayloadBehaviour>().PusherTarget;
        _pusher.destination = _target.position;       
        _pusherAni.SetBool("Alive", Pusher.Alive);
        _pusherAni.SetBool("Pushing", _pushing);
    }

PlayerBehaviour

Vector3 LookAround() Returns a Vector3 direction to manipulate the player’s rotation
Vector3 MoveAround() Returns a Vector3 direction to manipulate the player’s position
void Death() Changes the scene to the ‘game over’ scene after the player has died
bool CheckIfAlive Returns true if the player’s health is less than zero, if not it returns false
void ShotFire() Instantiates a gameobject then adds an calculated force to its velocity
void Awake() Initializes the player with an ‘Player’ ScriptableObject instance
void Start() Initializes the player’s member variables
void Update() Invokes ‘CheckIfAlive()’ every frame
void FixedUpdate() Checks for user input, updates the player position and rotation

Code Example:

Vector3 MoveAround()
    {
        //LEFT JOYSTICK CONTROLL
        var h = Input.GetAxis("HorizontalLeftJoy");
        var v = Input.GetAxis("VerticalLeftJoy");

        //WSAD CONTROLL
        //var h = Input.GetAxis("Horizontal");
        //var v = Input.GetAxis("Vertical");

        _animator.SetFloat("WalkMovement", Mathf.Abs(h) + Mathf.Abs(v));

        Vector3 _direction = new Vector3(h, 0, v);

        return _direction.normalized;
    } 

TowerBehaviour

void Awake() Initializes the tower with an instance of an ‘Tower’ ScriptableObject
void Start() Initializes various member variables
void Update() Invokes the onTowerHealthChange’s method ‘Invoke()’ with member variable ‘_tower.Health’ as an parameter

Code Example:

void Update () 
        {
            onTowerHealthChange.Invoke(_tower.Health);
	}
⚠️ **GitHub.com Fallback** ⚠️