- Home /
Why is only my last for-loop-button triggering?
Hey,
I have this drop-down menu in my game which uses a for-loop to display a button for every instance in a list:
if( selectedItem != emptyItem){
var rightClickRect : Rect = Rect( selectedItemLoc.x, selectedItemLoc.y, widthSlot * 3, selectedItem.usages.Count * widthSlot + widthSlot * 2 );
GUI.Box( rightClickRect, "Choose an option: ");
for( var u : int = 0; u < selectedItem.usages.Count; u++){
if( GUI.Button( Rect( rightClickRect.x + widthSlot * 0.2, rightClickRect.y + ( breedteSlot * u ) + widthSlot * 0.5, widthSlot * 2.6 , widthSlot ), selectedItem.usages[u].name)){
Debug.Log( "Called UseItem");
Debug.Log(u);
UseItem(selectedItem.usages[u]);
}
}
}
I'm sorry that the button/box location maths are so messy.
Anyway whenever the 'selectedItem' only has one instance in its 'usages' the button which the for-loop generates simply won't trigger, the Debug.Log won't show up. if it has 2 or more instances only the last button will trigger.
Any ideas why this is?
Thanks!
Answer by gameplay4all · May 06, 2014 at 10:11 PM
Well..
It turned out that using the 'if( Rect.Contains)' method does work, I still don't know why this won't work though. :/
anyway this works so yeah...
Your answer
Follow this Question
Related Questions
Tutorials for 2D game GUI 2 Answers
Problem with rect and touch 1 Answer
Centering Radial Menu 0 Answers
Bringing window to back GUI.BringWindowToBack() 0 Answers
Menu gui with background image 0 Answers