Example #1
0
    void Start()
    {
        //Set default values
        fl_MaxHealth      = 10f;
        fl_Health         = fl_MaxHealth;
        fl_InvisMaxEffect = 5f;
        fl_InvisEffect    = fl_InvisMaxEffect;
        fl_InvisCooldown  = 0f;
        bl_Instructions   = false;
        bl_Invis          = false;
        bl_InvisCooldown  = false;

        //Find the level map and obtain the script
        LM_Script = GameObject.Find("Level_Map").GetComponent <TL_LevelMediator>();

        //Find the data recorder and obtain the script
        DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();

        //Obtain the material from the renderer
        mt_PC = GetComponent <Renderer>().material;

        //Find the standard AI button in the canvas
        StandardAIButton = GameObject.Find("PC_Cam(Clone)/Canvas/ChoiceBox/StandardAIButton").GetComponent <Button>();

        //Set the function of the button from the level manager
        StandardAIButton.onClick.AddListener(delegate { LM_Script.StandardAIMode(); });

        //Find the dynamic AI button in the canvas
        DynamicAIButton = GameObject.Find("PC_Cam(Clone)/Canvas/ChoiceBox/DynamicAIButton").GetComponent <Button>();

        //Set the function of the button from the level manager
        DynamicAIButton.onClick.AddListener(delegate { LM_Script.DynamicAIMode(); });
    }
    void Start()
    {
        //Set initial values
        st_NPC_State       = "Patrol";
        st_NPC_PrevState   = st_NPC_State;
        fl_NPC_MaxHealth   = 8f;
        fl_NPC_Health      = fl_NPC_MaxHealth;
        fl_NPC_Attack      = 2f;
        fl_Attack_Range    = 4f;
        in_CurrentWaypoint = 0;

        //Create the text mesh and set the position
        go_TextMeshClone = Instantiate(go_TextMesh, new Vector3(transform.position.x, transform.position.y + 2f, transform.position.z), Quaternion.identity);

        //Set the rotation
        go_TextMeshClone.transform.eulerAngles = new Vector3(90, -90, 0);

        //Obtain the Nav Mesh Agent component
        nm_Agent = GetComponent <NavMeshAgent>();

        //Set default target position
        v3_NPC_TargetPos = transform.position;

        //Locate gameobjects and obtain their components
        LineOfSightScript = GetComponentInChildren <TL_NPCLineOfSight>();
        LM_Script         = GameObject.Find("Level_Map").GetComponent <TL_LevelMediator>();
        DataScript        = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();
        go_PC             = GameObject.Find("pf_PC(Clone)");
        PCScript          = go_PC.GetComponent <TL_PCStats>();
    }
Example #3
0
    void Start()
    {
        //Locate the gameobjects and obtain their scripts
        NPCScript  = GameObject.Find("pf_NPCGuard(Clone)").GetComponent <TL_NPC_FSM>();
        DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();

        //Destroy the bullet gameobject 1.5 seconds later
        Destroy(gameObject, 1.5f);
    }
    void Start()
    {
        //Obtain the scripts from the gameobject
        InventoryScript = GetComponent <TL_Inventory>();
        PCScript        = GetComponent <TL_PCStats>();

        //Find the data recorder gameobject and obtain the script
        DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();
    }
    void Start()
    {
        //Locate the PC
        PC = GameObject.FindGameObjectWithTag("PC");

        //Obtain the script from the parent gameobject
        NPCScript = GetComponentInParent <TL_NPC_FSM>();

        //Locate the gameobjects and obtain their scripts
        PCScript   = PC.GetComponent <TL_PCStats>();
        LM_Script  = GameObject.Find("Level_Map").GetComponent <TL_LevelMediator>();
        DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();
    }
Example #6
0
    void Start()
    {
        //Obtain the script from the PC
        PCScript = GetComponent <TL_PCStats>();

        //Find the data recorder and obtain the script
        DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();

        //Find the ammo counter gameobject
        AmmoCount = GameObject.Find("PC_Cam(Clone)/Canvas/AmmoCount");

        //Find the inventory tooltip
        InventoryTooltip = GameObject.Find("PC_Cam(Clone)/Canvas/InventoryBox/InventoryTooltip");

        //Initialize the buttons in an array
        InitializeInventory();
    }
    void Awake()
    {
        DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();

        //Set the layout of the level with a 2D int array
        in_LevelMap = new int[, ]
        {
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 17, 1, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 1, 0, 13, 0, 1, 1, 1, 0, 0, 1, 1 },
            { 1, 7, 2, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 1, 1 },
            { 1, 0, 0, 1, 1, 2, 1, 1, 1, 11, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 10, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 0, 0, 0, 1, 15, 1, 0, 0, 0, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 10, 1, 1, 1, 11, 1, 1, 0, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 0, 1, 1, 1, 2, 1, 1, 0, 0, 1, 1 },
            { 1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 2, 8, 1, 1 },
            { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 16, 0, 1, 1 },
            { 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 1, 12, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 1, 0, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 1 },
            { 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
            { 1, 0, 0, 1, 1, 1, 1, 0, 13, 1, 1, 1, 1, 0, 0, 1 },
            { 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
            { 1, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 2, 0, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 0, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 3, 0, 0, 0, 0, 0, 3, 1, 1, 1, 0, 5, 1 },
            { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 2, 0, 0, 0, 0, 4, 0, 1, 1, 1, 0, 2, 1 },
            { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1 },
            { 1, 1, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 1, 1, 0, 0, 1, 1, 1, 4, 0, 0, 0, 0, 4, 0, 1 },
            { 1, 1, 1, 3, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 },
            { 1, 9, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 },
            { 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 5, 14, 5, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        };

        //Loop through the 2D int array
        for (int x = 0; x < in_LevelMap.GetLength(0); x++)
        {
            for (int z = 0; z < in_LevelMap.GetLength(1); z++)
            {
                //If the gameobject level area is null in the 2D array
                //Map out in the 2D int array, which gameobject gets spawned in the scene depending on what value it is
                if (go_LevelArea[x, z] == null)
                {
                    //For example, if the value is 1 in the 2D int array, it spawns a wall in the level
                    if (in_LevelMap[x, z] == 1)
                    {
                        GameObject go_WallClone;
                        go_WallClone       = Instantiate(go_Wall, new Vector3(x, 1f, z), Quaternion.identity);
                        go_LevelArea[x, z] = go_WallClone;
                    }

                    if (in_LevelMap[x, z] == 2)
                    {
                        //Declare local variable for the nav mesh agent
                        NavMeshAgent NPCAgent;

                        //Instantiate the NPC
                        go_NPCClone = Instantiate(go_NPC, new Vector3(x, 1f, z), Quaternion.identity);

                        //Set the NPC to the gameobject array
                        go_LevelArea[x, z] = go_NPCClone;

                        //Obtain the nav mesh agent from the NPC
                        NPCAgent = go_LevelArea[x, z].GetComponent <NavMeshAgent>();

                        //Set a random number between 1 to 100 to the avoidance priority
                        NPCAgent.avoidancePriority = RandomizeNumber(1, 100);
                    }

                    if (in_LevelMap[x, z] == 3)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_A.Add(go_WPClone);
                        WP_List_A.Reverse();
                    }

                    if (in_LevelMap[x, z] == 4)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_B.Add(go_WPClone);
                    }

                    if (in_LevelMap[x, z] == 5)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_C.Add(go_WPClone);
                    }

                    if (in_LevelMap[x, z] == 6)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_D.Add(go_WPClone);
                    }

                    if (in_LevelMap[x, z] == 7)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_E.Add(go_WPClone);
                        WP_List_E.Reverse();
                    }

                    if (in_LevelMap[x, z] == 8)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_F.Add(go_WPClone);
                    }

                    if (in_LevelMap[x, z] == 9)
                    {
                        GameObject go_PCClone = Instantiate(go_PC, new Vector3(x, 1f, z), Quaternion.identity);;
                        PCScript = go_PCClone.GetComponent <TL_PCStats>();

                        GameObject go_CamClone = Instantiate(go_Cam, new Vector3(go_PCClone.transform.position.x + 2f, go_PCClone.transform.position.y + 13f, go_PCClone.transform.position.z), Quaternion.identity);
                        go_CamClone.transform.localEulerAngles = new Vector3(76f, 270f, 0);

                        go_LevelArea[x, z] = go_PCClone;
                    }

                    if (in_LevelMap[x, z] == 10)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_G.Add(go_WPClone);
                    }

                    if (in_LevelMap[x, z] == 11)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_H.Add(go_WPClone);
                    }

                    if (in_LevelMap[x, z] == 12)
                    {
                        go_WPClone = Instantiate(go_WP, new Vector3(x, 1f, z), Quaternion.identity);
                        WP_List_I.Add(go_WPClone);
                        WP_List_I.Reverse();
                    }

                    if (in_LevelMap[x, z] == 13)
                    {
                        GameObject HealthPillClone = Instantiate(go_HealthPill, new Vector3(x, 1f, z), Quaternion.identity);
                        HealthPillClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
                    }

                    if (in_LevelMap[x, z] == 14)
                    {
                        GameObject PistolClone = Instantiate(go_Pistol, new Vector3(x, 1f, z), Quaternion.identity);
                        PistolClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
                    }

                    if (in_LevelMap[x, z] == 15)
                    {
                        GameObject SmokeGrenadeClone = Instantiate(go_SmokeGrenade, new Vector3(x, 1f, z), Quaternion.identity);
                        SmokeGrenadeClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
                    }

                    if (in_LevelMap[x, z] == 16)
                    {
                        GameObject AmmoClone = Instantiate(go_Ammo, new Vector3(x, 1f, z), Quaternion.identity);
                        AmmoClone.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
                    }

                    if (in_LevelMap[x, z] == 17)
                    {
                        GameObject go_EndGameClone = Instantiate(go_EndGame, new Vector3(x, 1f, z), Quaternion.identity);
                        go_EndGameClone.transform.eulerAngles = new Vector3(90f, 270f, 0);
                    }
                }
            }
        }
        //Temporary lists to store certain elements from another list to swap them
        List <GameObject> Swap_List_E = new List <GameObject>();
        List <GameObject> Swap_List_I = new List <GameObject>();
        List <GameObject> Swap_List_C = new List <GameObject>();

        Master_List.Add(WP_List_F);
        for (int f = 0; f < WP_List_F.Count; f++)
        {
            WP_List_F[f].name = f.ToString();
        }

        Master_List.Add(WP_List_G);
        for (int g = 0; g < WP_List_G.Count; g++)
        {
            WP_List_G[g].name = g.ToString();
        }

        Master_List.Add(WP_List_H);
        for (int h = 0; h < WP_List_H.Count; h++)
        {
            WP_List_H[h].name = h.ToString();
        }

        Swap_List_E.Add(WP_List_E[2]);                          //Adds index 2 element of the WP List into index 1 element of the temporary list
        Swap_List_E.Add(WP_List_E[1]);                          //Adds index 1 element of the WP List into index 2 element of the temporary list
        WP_List_E.RemoveRange(1, 2);                            //Removes a range of old elements from the list
        WP_List_E.Insert(1, Swap_List_E[0]);                    //Inserts index 0 element of the temporary list into index 1 of the WP List
        WP_List_E.Insert(2, Swap_List_E[1]);                    //Inserts index 1 element of the temporary list into index 2 of the WP List

        //Adds the WP List into the master list
        Master_List.Add(WP_List_E);
        for (int e = 0; e < WP_List_E.Count; e++)
        {
            WP_List_E[e].name = e.ToString();
        }

        Master_List.Add(WP_List_D);
        for (int d = 0; d < WP_List_D.Count; d++)
        {
            WP_List_D[d].name = d.ToString();
        }

        Swap_List_I.Add(WP_List_I[2]);                  //Adds index 2 element of the WP List into index 1 element of the temporary list
        Swap_List_I.Add(WP_List_I[1]);                  //Adds index 1 element of the WP List into index 2 element of the temporary list
        WP_List_I.RemoveRange(1, 2);                    //Removes a range of old elements from the list
        WP_List_I.Insert(1, Swap_List_I[0]);            //Inserts index 0 element of the temporary list into index 1 of the WP List
        WP_List_I.Insert(2, Swap_List_I[1]);            //Inserts index 1 element of the temporary list into index 2 of the WP List
        Master_List.Add(WP_List_I);
        for (int i = 0; i < WP_List_I.Count; i++)
        {
            WP_List_I[i].name = i.ToString();
        }

        Master_List.Add(WP_List_A);
        for (int a = 0; a < WP_List_A.Count; a++)
        {
            WP_List_A[a].name = a.ToString();
        }

        Swap_List_C.Add(WP_List_C[2]);                          //Adds index 2 element of the WP List into index 1 element of the temporary list
        Swap_List_C.Add(WP_List_C[1]);                          //Adds index 1 element of the WP List into index 2 element of the temporary list
        WP_List_C.RemoveRange(1, 2);                            //Removes a range of old elements from the list
        WP_List_C.Insert(1, Swap_List_C[0]);                    //Inserts index 0 element of the temporary list into index 1 of the WP List
        WP_List_C.Insert(2, Swap_List_C[1]);                    //Inserts index 1 element of the temporary list into index 2 of the WP List
        Master_List.Add(WP_List_C);
        for (int c = 0; c < WP_List_C.Count; c++)
        {
            //Name the waypoints depending on the value from the for loop
            WP_List_C[c].name = c.ToString();
        }

        Master_List.Add(WP_List_B);
        for (int b = 0; b < WP_List_B.Count; b++)
        {
            //Name the waypoints depending on the value from the for loop
            WP_List_B[b].name = b.ToString();
        }

        for (int x = 0; x < in_LevelMap.GetLength(0); x++)
        {
            for (int z = 0; z < in_LevelMap.GetLength(1); z++)
            {
                if (go_LevelArea[x, z] != null)
                {
                    //If the gameobject in the 2D array is the NPC
                    if (go_LevelArea[x, z].transform.tag == "NPC")
                    {
                        //Obtain the script from the NPC
                        NPCScript = go_LevelArea[x, z].GetComponent <TL_NPC_FSM>();

                        //Assign the waypoints for the NPC
                        NPCScript.WP_Assignment(Master_List[in_Master_List_Index]);

                        //Assign the ID for waypoints
                        NPCScript.ID_TrailAssignment(in_Master_List_Index);

                        //Increment the index for the master list
                        in_Master_List_Index++;

                        //If it is more than 7, break the loop
                        if (in_Master_List_Index > 7)
                        {
                            break;
                        }
                    }
                }
            }
        }
        //Build the navmesh
        #if UNITY_EDITOR
        UnityEditor.AI.NavMeshBuilder.BuildNavMesh();
        #endif
    }
 void Start()
 {
     //Locate the gameobject and obtain the script
     DataScript = GameObject.Find("Data_Recorder").GetComponent <TL_RecordData>();
 }