- Home /
how to use EditorGUI.IntField
The API only shows it in java. I get errors in C#. Does this mean I can't make an intfield in c#? If someone would please explain that to me, that would be great.
Answer by taxvi · Dec 02, 2014 at 09:21 AM
it works fine for me, this is the example script from the Unity docs translated into c#. Put it in the Assets/Editor folder (otherwise it won't work!):
using UnityEngine;
using System.Collections;
using UnityEditor;
// Editor Script that clones the selected GameObject a number of times.
class EditorGUILayoutIntField : EditorWindow {
int clones = 1;
[MenuItem("Examples/Clone Object")]
static void Init() {
EditorWindow window = GetWindow<EditorGUILayoutIntField>();
window.Show();
}
void OnGUI() {
int sizeMultiplier = EditorGUILayout.IntField("Number of clones:", clones);
if(GUILayout.Button("Clone!"))
for(var i = 0; i < clones; i++)
Instantiate(Selection.activeGameObject, Vector3.zero, Quaternion.identity);
}
}
So it needs to be in a folder named Editor? And where are you defining the position of the box on the GUI?
Intereting seeing that you put "var" on line 21. Thats Java. Should work the same if you remove it.
var works just the same in c#. I just copy-pasted the javascript and translated it line by line. Yes, it needs to be in a folder called Editor. I forgot to mention that after you place the script in the folder and have no errors popping up you should hover over the menus on the top (File / Edit / Components ... ) to let Unity refresh it, or the new menu does not show up.
Your answer
![](https://koobas.hobune.stream/wayback/20220613172940im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Not working gui buttons 1 Answer
why is my GUI script bugging other GUI scripts? 0 Answers
What are these things doing in C#? 3 Answers