- Home /
Event.button activating constantly?
When I am running, the code that follows, the code runs in a constant loop. I want it to, among other things, only run when the user clicks on the left mouse button. Here is the code:
private void Update()
{
if(TilePainterEditor.e != null &&
textures[folderIndex][fileIndex] != null &&
toolSelected == 1 &&
TilePainterEditor.e.button == 0) /* This is where I check if it's clicked, The rest of the code is unimportant*/
{
GameObject g = new GameObject(textures[folderIndex][fileIndex].name);
g.AddComponent<SpriteRenderer>();
g.GetComponent<SpriteRenderer>().sprite = Sprite.Create(textures[folderIndex][fileIndex],
new Rect(0, 0, textures[folderIndex][fileIndex].width, textures[folderIndex][fileIndex].height),
Vector2.zero);
Vector3 mouseRPos = TilePainterEditor.Position;
Instantiate(g,new Vector3(mouseRPos.x,mouseRPos.y, zAxis), Quaternion.identity);
}
}
Also, I can't use Input.GetMouseButtonDown() because that doesn't run in the editor view.
void Update(){
if(Input.Get$$anonymous$$ouseButtonDown(0)){ //or Input.GetButtonDown("Fire1")
//your code
}
}
Please read my entire question, including the bottom of the question.
Yeah my bad well the end of the question doesn't help but the tags do. You should add e.type == EventType.mouseDown but then again it will gonna be true for several times. I guess inside your Custom Editor you have the line: e = Event.current inside OnGUI(), the problem here is that OnGUI() is called far less times than Update() so for several frames e.button ==0 && e.type == EventType.mouseDown gonna be true with a single click. Now either if your class above supports OnGUI() move it there or move the above code inside a method and call the method from your custom Editor through OnGUI(). Cheers.
Your answer
Follow this Question
Related Questions
Detect Enter Key Event with GUILayout.TextField Focused 1 Answer
Popup options not changing in custom editor script 0 Answers
Listen to Keyboard Events on EditorWindow 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers