Mission Objectives

Next I had to set up the objectives for the level, which Connor decided will be using one computer, which unlocks the ability to use the second one, which then spawns more guards and the player has to go back to the building he started at. To do this, I edited the ‘player_computer’ script, by firstly setting the second computer to only activate after the first one has been used, and then enabling the guards after using the second one. It was pretty simple to set up, but it did take me a while to set up the guards and their waypoints.

Here’s the updated script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player_computer : MonoBehaviour 

    public Animator anim;
    private bool canInteract;
    private bool isInteracting;
    public bool hasUsed;
    private GameObject g16;
    private GameObject g17;
    private GameObject g18;
    private GameObject g19;
    private GameObject g20;
    private GameObject g21;
    private GameObject g22;
    private GameObject g23;
    private GameObject g24;
    private GameObject g25;
    private GameObject g26;
    private GameObject g27;
    private GameObject g28;
    private GameObject g29;
    private GameObject g30;

    void Start () 
        anim = GetComponent<Animator>();
        canInteract = false;
        isInteracting = false;
        hasUsed = false;
        g16 = GameObject.Find (Light_Guard16);
        g16.SetActive (false);
        g17 = GameObject.Find (Light_Guard17);
        g17.SetActive (false);
        g18 = GameObject.Find (Light_Guard18);
        g18.SetActive (false);
        g19 = GameObject.Find (Light_Guard19);
        g19.SetActive (false);
        g20 = GameObject.Find (Light_Guard20);
        g20.SetActive (false);
        g21 = GameObject.Find (Light_Guard21);
        g21.SetActive (false);
        g22 = GameObject.Find (Light_Guard22);
        g22.SetActive (false);
        g23 = GameObject.Find (Light_Guard23);
        g23.SetActive (false);
        g24 = GameObject.Find (Light_Guard24);
        g24.SetActive (false);
        g25 = GameObject.Find (Light_Guard25);
        g25.SetActive (false);
        g26 = GameObject.Find (Light_Guard26);
        g26.SetActive (false);
        g27 = GameObject.Find (Light_Guard27);
        g27.SetActive (false);
        g28 = GameObject.Find (Light_Guard28);
        g28.SetActive (false);
        g29 = GameObject.Find (Light_Guard29);
        g29.SetActive (false);
        g30 = GameObject.Find (Light_Guard30);
        g30.SetActive (false);
    void OnTriggerEnter(Collider other)
        if (other.tag == Computer)
            canInteract = true;
            GameObject.Find (TextInteract).GetComponent<MeshRenderer> ().enabled = true;

    void OnTriggerExit(Collider other)
        if (other.tag == Computer)
            canInteract = false;
            GameObject.Find (TextInteract).GetComponent<MeshRenderer> ().enabled = false;

    void Update () 
        if (Input.GetKeyDown (e) && (canInteract == true)) 
            transform.rotation = Quaternion.Euler(0f, 0f, 0f);
            anim.Play (Interact, 1, 0f);
            isInteracting = true;
            GameObject.Find (TextInteract).GetComponent<MeshRenderer> ().enabled = false;
            hasUsed = true;
            if (GameObject.Find (Computer2).GetComponent<BoxCollider> ().enabled == true) 
                g16.SetActive (true);
                g17.SetActive (true);
                g18.SetActive (true);
                g19.SetActive (true);
                g20.SetActive (true);
                g21.SetActive (true);
                g22.SetActive (true);
                g23.SetActive (true);
                g24.SetActive (true);
                g25.SetActive (true);
                g26.SetActive (true);
                g27.SetActive (true);
                g28.SetActive (true);
                g29.SetActive (true);
                g30.SetActive (true);
            GameObject.Find (Computer2).GetComponent<BoxCollider> ().enabled = true;
            GameObject.Find (Computer1).GetComponent<BoxCollider> ().enabled = false;

        if (GetComponent<Animator> ().GetCurrentAnimatorStateInfo (0).IsName (Interact)) 
            isInteracting = true;
            GetComponent<PlayerMove> ().enabled = false;
            GetComponent<RotationCheck> ().enabled = false;
            GetComponent<player_animation> ().enabled = false;
            canInteract = false;

        if (!GetComponent<Animator> ().GetCurrentAnimatorStateInfo (0).IsName (Interact))
            isInteracting = false;
            GetComponent<PlayerMove> ().enabled = true;
            GetComponent<RotationCheck> ().enabled = true;
            GetComponent<player_animation> ().enabled = true;

And here’s a video of it working (on the video I move the player by dragging the object in the Scene editor to make the video shorter, but it also works when played normally):


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s