- Home /
c# - void method from external class.
Im trying to make a class file that can be called from any other script easily that just displays some text. But i cant get it to work, The class file:
using UnityEngine;
using System.Collections;
namespace DevText{
class Dev : MonoBehaviour {
void ShowText()
{
GUILayout.BeginArea(new Rect(15, (Screen.height - 20),(Screen.width),50));
GUILayout.Label("Version: 0.0.1 | build 010 | "+ Application.platform + " | " + Application.unityVersion + " | Kennyist.com ","Version");
GUILayout.EndArea();
}
}
}
But when i try to use it on another script (does have "Using DevText;") The only option i get is "DevText.Dev" or "dev.Destroy/equals ETC".
How would you go about doing this?
Thanks.
Answer by KoningStoma · Jan 23, 2013 at 11:10 AM
Use the "static" keyword.
public static void ShowText()
Answer by CodeMasterMike · Jan 23, 2013 at 06:29 AM
Try to set public in front of the ShowText function.
public void ShowText()
{
// code...
}
since I believe it sets it to private by default, if you don't set it yourself.
That hasn't worked either, I've even tried putting the main script in the same namespace but it still does not want to work.
You need to make your class public as well:
public class Dev : $$anonymous$$onoBehaviour {
Your answer
Follow this Question
Related Questions
Problems with instantiation... 1 Answer
When your GUI is gluey, what to do-ey? 1 Answer
System.NullReferenceException 1 Answer
Script work in editor but not in build 0 Answers
Does every c# class need to have its own script with the class' name? 4 Answers