Question by
whaleinthesea · Sep 02, 2015 at 06:38 PM ·
c#scripting problemguiboxvoid
How to instantiate (MonoBehaviour) script multiple times and call void?
I have a C# script: box.cs with a void in it which creates a GUI.box. In an other script I want to call that void like this var script1 = box; box.createBox(height,width,x,y);
Comment
Best Answer
Answer by Cherno · Sep 02, 2015 at 08:29 PM
Ok.... The "void in it" is just what is called a return type of a method. Just to be clear about that. What you were probably trying to say is that you have a script that has a method in it which creates a GUI.box.
Anyway, you are on the right track. In your second script, make the script1 variable public, declare it with a proper Type, and drag the first script into it's field in the inspector. Then, acees the script reference and call the method.
public YourFirstScriptType script1;
void Start() {
script1.createBox(height,width,x,y);
}