- Home /
Event.type check doesnt work inside nested list
Hi, guys. I've tried to google it, but it seems nobody has the exact same problem before, that makes me think that im doing something wrong, but don't know what, so any help will be appreciated. First, the code:
function OnGUI(){
if(showInventory){
for(var col = 0; col < 5; col++){
for (var raw = 0; raw < 3; raw++){
var rect : Rect = Rect(col * 50, raw * 50, 50, 50);
var cell = GUI.Button(rect, invIndex[col, raw]);
if (Event.current.type == EventType.MouseDown && invIndex[col, raw] && rect.Contains(Event.current.mousePosition)){
//do things
}
I'm trying to create Drag&Drop behavior for inventory. I draw inventory with nested list of GUI buttons and then i want to check for MouseDown on one. This code:
if (Event.current.type == EventType.MouseDown){
does not return true if it inside of the nested list creation. Although if this code is outside of the nested list, then it works as intended. The problem is: i also want to check if this event happend over the exact button, so do it like that;
Rect(col * 50, raw * 50, 50, 50).Contains(Event.current.mousePosition)
as you can see, i use variables from this nested list creation, so i can't check for mouseDown from outside of the "for loop".
I've also tried to replace Event stuff with Input.GetMouseButtonDown, but it causes another problem, because Input check happens in Update and GUI in FixedUpdate, so sometimes Input returns true twice for one frame.