Hello,
What have i made
I have build a HUD which has a for loop which creates 7 buttons on the HUD. The buttons have a picture of an item in them. When I press on of the buttons. The background of the hud is placed outside the screen. This makes it seem outside the screen.
What am i trying to make
When I press the right mouse button, the hud appears. When I then click one of the buttons, they, and the hud disappears.
Problem
I have no idea how to access the buttons since i have not created them through an instance. Or anything. I till today didn’t even know you could create stuff within an if statement.
If someone could explain what I am doing wrong. Or what I should do to make it possible to access the buttons properties. Please do.
My code:
public var visibility:boolean;
//previewObjects which holds all object preview textures
public var previewObjects:Texture2D[];
private var previewObjectPositions:Rect[];
//objectPreviewSize is the Width and the Height og the preview button on the GUI
public var objectPreviewSize:Vector2;
//contentStartingPosition is the position of the GUI inventory+startposition
public var contentStartingPosition:Vector2;
//contentOffsetPosition is a variable, added to all the previewbutton's position
public var contentOffsetPosition:Vector2;
//contentSeparation is the width between the preview objects
public var contentSeparation:float;
function OnGUI() {
for(var i:int = 0; i < previewObjects.length; i++)
{
if (GUI.Button(Rect(contentStartingPosition.x+(objectPreviewSize.x+contentSeparation)*i+contentOffsetPosition.x, contentStartingPosition.y+contentOffsetPosition.y, objectPreviewSize.x, objectPreviewSize.y), previewObjects[i]))
{
GameObject.Find("GUI").GetComponent("GuiInventoryVisibility").hide();
GameObject.Find("Main Camera").GetComponent("CharacterMotor").canControl = true;
GameObject.Find("Main Camera").GetComponent(MouseLook).Enable();
}
}