so i’ve seen tons of different ways to call methods from other files, but I’m still really confused at which one is the correct one to use in my case. The way I have it set up right now doesn’t work unfortunately. Could anyone help me out with as to why it doesn’t?
Okay, I have two scripts right now Menu.cs & ScreenFadeInOut.cs. What I want to happen is to be able to click the GUI button created and displayed from Menu.cs and once clicked, call the Fade() method from ScreenFadeInOut.cs.
Here’s ScreenFadeInOut.cs:
using UnityEngine;
using System.Collections;
public class ScreenFadeInOut : MonoBehaviour
{
public static ScreenFadeInOut Instance;
Shader s1;
Shader s2;
public float change = .01f;
// Use this for initialization
void Start ()
{
Instance = this;
gameObject.renderer.material.color = Color.black;
s1 = Shader.Find("Diffuse");
s2 = Shader.Find("Transparent/Diffuse");
if (gameObject.renderer.material.shader == s1)
{
gameObject.renderer.material.shader = s2;
}
}
// Update is called once per frame
void Update ()
{
}
public void Fade()
{
gameObject.renderer.material.color -= new Color(0,0,0,change);
}
}
And here’s Menu.cs
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour
{
//is the menu showing?
bool menu;
//how fast intro text scrolls.
public int txtSpeed = 30;
//button width.
private int bWidth = 200;
//button height.
private int bHeight = 50;
// Use this for initialization
void Start ()
{
//start with menu showing.
menu = true;
}
// Update is called once per frame
void Update ()
{
//if Escape key is pressed & released, hide the menu and show it if pressed again.
if (Input.GetKeyUp (KeyCode.Escape))
{
menu = !menu;
}
}
//draws all GUI on the screen
void OnGUI()
{
//if the menu is open
if (menu == true)
{
//create a button centered in the middle of the screen and if it's clicked, close the menu.
if (GUI.Button (new Rect(Screen.width/2 - bWidth/2, Screen.height/2 - bHeight/2, bWidth, bHeight), "Start"))
{
menu = false;
ScreenFadeInOut.Instance.Fade();
}
}
//intro text.
//GUI.Label(new Rect(Screen.width/2, 500 + (Time.time*-txtSpeed),500, 500),"Some long text");
}
}
As always any help is appreciated!
EDIT: the strangest part is I’m not getting any errors!