Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Accessing another script function does not work. Help please

Discussion in 'Scripting' started by SirMarley, Sep 24, 2014.

  1. SirMarley

    SirMarley

    Joined:
    Jul 26, 2014
    Posts:
    115
    I don´t know what am I doing wrong, but I can´t make it work:

    I have 2 scripts:
    Map.cs and LabelInMap.cs

    They are both attached to the main camera.

    LabelInMap accesses Map for its variables, and it works fine...

    but Map needs to call a function from LabelInMap and it does not work

    Any help, please?

    This is the script (it does not throw me an error, it just does not do anything)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Map : MonoBehaviour {
    5.  
    6.     public Texture MapTexture;
    7.     public int lSel;
    8.  
    9.     public bool _luna;
    10.     public bool _marte;
    11.     public bool _venus;
    12.     public bool _mercurio;
    13.     public bool _jupiter;
    14.     public bool _saturno;
    15.     public bool _neptuno;
    16.     public bool _urano;
    17.     public bool _pluton;
    18.     public bool _sol;
    19.  
    20.     public LabelInMap label;
    21.  
    22.     void Start()
    23.     {
    24.         lSel = PlayerPrefs.GetInt("EngSpaChi");
    25.         label = GetComponent<LabelInMap>();
    26.     }
    27.  
    28.     void OnGUI()
    29.     {
    30.         GUI.depth = 1;
    31.         GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), MapTexture);
    32.  
    33.         if (GUI.Button(new Rect(0, 0, Screen.width * .15f, Screen.height * .25f), "", GUIStyle.none))
    34.         {
    35.             Debug.Log("Sun Pressed");
    36.             _jupiter = false;
    37.             _luna = false;
    38.             _marte = false;
    39.             _mercurio = false;
    40.             _neptuno = false;
    41.             _pluton = false;
    42.             _saturno = false;
    43.             _urano = false;
    44.             _venus = false;
    45.             _sol = true;
    46.             label.ShowLabel();  // the other script has a public void ShowLabel function with a Debug.Log inside
    47.         }
    48. }
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Can you show the the function ShowLabel ?
    I cant find any error in your Map.cs file.
     
  3. SirMarley

    SirMarley

    Joined:
    Jul 26, 2014
    Posts:
    115
    I got it.

    It was accessing the function... but it seems I had kind of a conflict between bools... I had map._mars and BossBool._mars...

    Now I will go back to the other questions, because my label still not appearing (I have GUI.depth = 1 for the GUI.DrawTexture and in the other script I have GUI:depth = 0 for the GUI:Label but my label does not show up)
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Those two wouldn't get in conflict with each other, as they belong to different classes.
    You can have as many classes as you want and all can have a boolean _mars.

    It's better to see the script, but one thing i guess at this point is that you draw a GUI.Label in your method ShowLabel(). This method is only called once when you clicked the button, you won't see it at all. You may wanna set a bool to true when firing that method and draw the label as long as the bool is true. That's the easiest solution.
     
    SirMarley likes this.