Search Unity

Scripts working together

Discussion in 'Scripting' started by Flutschi, Oct 13, 2015.

  1. Flutschi

    Flutschi

    Joined:
    Oct 10, 2015
    Posts:
    7
    Hi there,

    Im new to Unity and C# and im playing around with a small game tutorial and im on the point where i want to build in a small mission, click on a computer and then walk to a collider with a trigger in it.

    Now i have to make scripts working with variables from other scripts and there i fail :D

    i can somehow get to work that a dialogue is popping up from a script but somehow i cant figure out how to set a bool to true in another script, kinda strange ;)

    And on a simular note, i work with public variables and drag&drop the objects in the unity into the slot where it should be, i red about a FIND and GETCOMPONENT method but i dont know which one i should use... what is the difference between those 2 methods?



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Computer : MonoBehaviour {
    5.  
    6.     public Dialogue _dialoguescript;
    7.     string[] DialogueStrings;
    8.  
    9.     public GameObject TextBox ;
    10.     public GameObject HintergrundTextBox;
    11.  
    12.     public bool Mission1TriggerBox;  
    13.  
    14.     public bool _FirstMissionEnabled = false;
    15.  
    16.  
    17.     void Start()
    18.     {
    19.         // panel = GameObject.Find("Dialogue Image");
    20.         TextBox.SetActive(false);
    21.         HintergrundTextBox.SetActive(false);
    22.  
    23.     }
    24.  
    25.     void OnTriggerStay2D(Collider2D other){
    26.         if (Input.GetKeyDown ("t"))
    27.         {
    28.             //print("Computer was activated");
    29.             TextBox.SetActive(true);
    30.             HintergrundTextBox.SetActive(true);
    31.  
    32.             DialogueStrings = new string[3];
    33.             DialogueStrings[0] = "Hi there";
    34.             DialogueStrings[1] = "Lets go to the first Mission!";
    35.             DialogueStrings[2] = "Go to the Gate!";
    36.             _dialoguescript.StartCoroutine(_dialoguescript.StartDialogue(DialogueStrings));
    37.  
    38.             Mission1TriggerBox._isEnabled = true;    <-------------- ERROR
    39.  
    40.          
    41.             //panel.SetActive(false);
    42.         }
    43.     }
    44.  
    45.     void OnTriggerExit2D(Collider2D other) {
    46.         Debug.Log ("Und weg..");
    47.         TextBox.SetActive(false);
    48.         HintergrundTextBox.SetActive(false);
    49.     }
    50. }
    51.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Misison1 : MonoBehaviour {
    5.  
    6.  
    7.     static bool _M1Enabled;
    8.  
    9.     public Dialogue _dialoguescript;
    10.     string[] DialogueStrings;
    11.  
    12.  
    13.     void OnTriggerEnter2D(Collider2D other)
    14.     {
    15.         if (_isEnabled == true)
    16.         {
    17.  
    18.             Debug.Log("YeeY");   <--------------- THIS SHOULD HAPPEN BUT IT DOESNT :(
    19.  
    20.         }
    21.     }
    22. }
    23.  

    The green text never gets displayed. :(


    Thanks for any Help!