Advertisement
EmmyDev

Game Task Manager

Dec 29th, 2022 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.75 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.AI;
  6. using TMPro;
  7.  
  8. public class TaskM : MonoBehaviour
  9. {
  10.     public bool freeTime = true;
  11.  
  12.     public bool generateNewTask;
  13.  
  14.     public bool startAgroTimer;
  15.     public bool startNewTaskTimer;
  16.     private float Agrotimer;
  17.     private float reverseAgroTimer;
  18.     private float NewTaskTimer;
  19.     private int RemmeberedNum = 0;
  20.     public int NewNumber = 0;
  21.  
  22.     private bool _managerActive = false;
  23.  
  24.     public Text managerT;
  25.     private TextMeshProUGUI subtitle;
  26.    
  27.     public GameObject player;
  28.     public GameObject phone;
  29.    
  30.     public NavMeshAgent agent;
  31.     public GameObject[] TaskObjects;
  32.    
  33.     public GameObject minimap;
  34.    
  35.     private Transform taskPos;
  36.     public LineRenderer lineRenderer;
  37.  
  38.     public GameObject managerPapp;
  39.     // Update is called once per frame
  40.     void Update()
  41.     {  
  42.  
  43.         //keeps agro if agro is active once
  44.         if(_managerActive == true)
  45.         {
  46.             spawnManager();
  47.         }
  48.  
  49.  
  50.         //print(Agrotimer);
  51.         if(Agrotimer > 0){
  52.             NavMeshPath path = new NavMeshPath();
  53.             NavMesh.CalculatePath(player.transform.position, taskPos.Find("navPos").gameObject.transform.position, NavMesh.AllAreas, path); //Saves the path in the path variable.
  54.             Vector3[] corners = path.corners;
  55.             lineRenderer.positionCount = corners.Length;
  56.             lineRenderer.SetPositions(corners);
  57.            
  58.         }else{
  59.             lineRenderer.positionCount = 0;
  60.         }
  61.  
  62.  
  63.  
  64.  
  65.         if(generateNewTask == true){
  66.             //creates new task
  67.             newTask();
  68.         }
  69.         else if(generateNewTask == false){
  70.             //remebers last task
  71.             RemmeberedNum = NewNumber;
  72.         }
  73.         //catalouges all task-objects
  74.         TaskObjects = GameObject.FindGameObjectsWithTag("Task");
  75.        
  76.  
  77.        
  78.         //checks if task is complete before agro timer runs out.
  79.         if(startAgroTimer == true && TaskObjects[NewNumber].GetComponent<Interacted>().enabled == false){
  80.             freeTime = true;
  81.             startAgroTimer = false;
  82.            
  83.            
  84.         }
  85.        
  86.         //strats agro timer if task isnt completed.
  87.         if(startAgroTimer == true){
  88.             phone.GetComponent<Animator>().SetInteger("state", 1);
  89.             Agrotimer += Time.deltaTime;
  90.            
  91.            
  92.             managerT.text = ("Follow the map and interact with the " + TaskObjects[NewNumber].name + " <color=blue>" + (60f - Agrotimer).ToString("0") + "</color>");
  93.             if(Agrotimer > 60f){
  94.                 //spawns Manager if task isnt Complete whitin 60s
  95.                 spawnManager();
  96.                 _managerActive = true;
  97.             }
  98.         }else if(startAgroTimer == false){
  99.             Agrotimer = 0f;
  100.         }
  101.  
  102.         //starts freetime before new task
  103.         if(freeTime == true){
  104.             subtitle = GameObject.FindGameObjectWithTag("sub").GetComponent<TextMeshProUGUI>();
  105.             subtitle.text = "";
  106.             phone.GetComponent<Animator>().SetInteger("state", 2);
  107.             NewTaskTimer += Time.deltaTime;
  108.             managerT.text = " ";
  109.             if(NewTaskTimer > 45f){
  110.                 generateNewTask = true;
  111.                
  112.                 managerT.text = "not freetime.";
  113.                 freeTime = false;
  114.             }
  115.         }
  116.         else if(freeTime == false){
  117.             NewTaskTimer = 0f;
  118.         }
  119.  
  120.        
  121.     }
  122.     public void newTask(){
  123.         //Creates new different task from last one
  124.         NewNumber = Random.Range(0, TaskObjects.Length);
  125.         if(RemmeberedNum != NewNumber){
  126.  
  127.             TaskObjects[NewNumber].GetComponent<Interacted>().enabled = true;
  128.            
  129.             //Debug.Log(TaskObjects[NewNumber].name);
  130.             managerT.text = "new task created";
  131.             //startPhoneCallAudio(NewNumber);
  132.             Agrotimer = 0f;
  133.             startAgroTimer = true;
  134.             generateNewTask = false;
  135.             phone.GetComponent<Animator>().SetInteger("state", 1);
  136.             TaskObjects[NewNumber].GetComponent<Interacted>().TaskStarted();
  137.             taskPos = TaskObjects[NewNumber].transform;
  138.  
  139.         }else{
  140.             managerT.text = "creating...";
  141.         }
  142.        
  143.     }
  144.     public void spawnManager(){
  145.         //some manager spawning code
  146.         managerT.text = "Manager in the house!";
  147.         agent.GetComponent<BoxCollider>().enabled = true;
  148.         managerPapp.GetComponent<SpriteRenderer>().enabled = true;
  149.         agent.SetDestination(player.transform.position);
  150.        
  151.     }
  152.     void navLines(Transform taskPos){
  153.         //navmesh lines
  154.            
  155.     }
  156. }
  157.    
  158.  
  159.  
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement