- Home /
I am trying to call another function in another script for an editor layout script.
I am creating a button in the editor GUI and am having trouble calling a function in another script. For reference the other script is titled meshGen and the function is called buildMesh.
The error is with the regen.buildmesh command and for some reason I cannot understand the reason. (not much programming experience here)
Also before its mentioned not sure if UnityEngine or System.Collections were going to be used so I left them for posterity purposes.
EDIT: The error is with line 13.
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor(typeof(meshGen))]
public class TileMapRegen : Editor {
public override void OnInspectorGUI() {
base.OnInspectorGUI();
if(GUILayout.Button("Regenerate")){
meshGen regen = meshGen(target);
regen.buildMesh;
}
}
}
Answer by gregzo · Jul 29, 2013 at 02:05 PM
Please have a look at catlikecoding's excellent tutorial on editor scripts. It starts out with decribing how to create meshes, but soon enough it goes into a lot of very useful editor code.
Below is an example of how catlike does things.
Note : you should follow conventions, class and method names start with uppercase, variables use camelCase. Also, you're forgetting the () after regen.buildMesh.
private SerializedObject serializedObj;
void OnEnable()
{
serializedObj = new SerializedObject(target);
}
public override void OnInspectorGUI ()
{
serializedObj.Update();
meshGen regen = (meshGen)target;
regen.buildMesh();
}
Thank you for the help. The link was perfect. And will help with countless other things. and another thank you for helping me with my coding conventions. Like I said relatively new here.
Your answer
Follow this Question
Related Questions
Iphone gui text 2 Answers
Live system/Score, etc. 1 Answer
How to detect Mouse over gui and guilayout elements? 4 Answers
Get variable from another object 1 Answer