Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Coroutine help.

Discussion in 'Scripting' started by ToxicSeaSponge, Sep 14, 2018.

  1. ToxicSeaSponge

    ToxicSeaSponge

    Joined:
    Sep 25, 2017
    Posts:
    6
    Hi,
    so I have a coroutine for quest entries that appear on the screen. it supposed to occur after I accept the quest from a board, but the co routine only starts after I interact with the quest board a second time and it shows up while I'm looking at the quest and not after, looked over it and the tutorial a good number of times, but still have no idea, any ideas?

    This is the ui button script.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Quest001Buttons : MonoBehaviour
    7. {
    8.  
    9.     public GameObject ThePlayer;
    10.     public GameObject NoticeCam;
    11.     public GameObject UIQuest;
    12.     public GameObject ActiveQuestBox;
    13.     public GameObject Objective01;
    14.     public GameObject Objective02;
    15.     public GameObject Objective03;
    16.  
    17.     public void AcceptQuest()
    18.     {
    19.         ThePlayer.SetActive (true);
    20.         NoticeCam.SetActive (false);
    21.         UIQuest.SetActive (false);
    22.         StartCoroutine(SetQuestUI());
    23.     }
    24.  
    25.     IEnumerator SetQuestUI()
    26.     {
    27.         ActiveQuestBox.GetComponent<Text>().text = "My First Weapon";
    28.         Objective01.GetComponent<Text>().text = "Reach the clearing in the wood";
    29.         Objective02.GetComponent<Text>().text = "Open the chest";
    30.         Objective03.GetComponent<Text>().text = "Retrieve the weapon";
    31.         QuestManager.ActiveQuestNumber = 1;
    32.         yield return new WaitForSeconds(0.5f);
    33.         ActiveQuestBox.SetActive(true);
    34.         yield return new WaitForSeconds(1);
    35.         Objective01.SetActive(true);
    36.         yield return new WaitForSeconds(0.5f);
    37.         Objective02.SetActive(true);
    38.         yield return new WaitForSeconds(0.5f);
    39.         Objective03.SetActive(true);
    40.         yield return new WaitForSeconds(9);
    41.         ActiveQuestBox.SetActive(false);
    42.         Objective01.SetActive(false);
    43.         Objective02.SetActive(false);
    44.         Objective03.SetActive(false);
    45.     }
    46.  
    47.     public void DeclineQuest()
    48.     {
    49.         ThePlayer.SetActive(true);
    50.         NoticeCam.SetActive(false);
    51.         UIQuest.SetActive(false);
    52.     }
    53. }
    and this is the quest script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Quest001 : MonoBehaviour
    6. {
    7.     public float TheDistance;
    8.     public GameObject ActionDisplay;
    9.     public GameObject ActionText;
    10.     public GameObject UIQuest;
    11.     public GameObject ThePlayer;
    12.     public GameObject NoticeCam;
    13.    
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         TheDistance = PlayerCasting.DistanceFromTarget;
    19.     }
    20.     void OnMouseOver()
    21.     {
    22.         if (TheDistance <= 3)
    23.         {
    24.          
    25.             ActionDisplay.SetActive(true);
    26.             ActionText.SetActive(true);
    27.         }
    28.  
    29.         if (Input.GetButtonDown("Action"))
    30.         {
    31.             if (TheDistance <= 3)
    32.             {
    33.              
    34.                 ActionDisplay.SetActive(false);
    35.                 ActionText.SetActive(false);
    36.                 UIQuest.SetActive(true);
    37.                 NoticeCam.SetActive(true);
    38.                 ThePlayer.SetActive(false);
    39.                 Cursor.lockState = CursorLockMode.None;
    40.                 Cursor.visible = true;
    41.  
    42.             }
    43.         }
    44.     }
    45.  
    46.     void OnMouseExit()
    47.     {
    48.         ActionDisplay.SetActive(false);
    49.         ActionText.SetActive(false);
    50.  
    51.     }
    52. }
    53.  
    54.  
    55.  
    56.  
    57.  
    58.  
    59.  
    60.  
    61.