Hello,
I am creating a script that I can use to create a GUI using GUI Textures. The following script is almost where I want it but not quite. I’ve only just started using Arrays and I’m finding it quite confusing.
var buttonHeight : float;
var buttonWidth : float;
var buttons : GameObject[];
function Start () {
transform.position = Vector3.zero;
guiTexture.pixelInset = Rect(Screen.width - buttonWidth,Screen.height - buttonHeight, buttonWidth, buttonHeight);
for (var i : int = 0; i<buttons.Length; i++){
Debug.Log ("this is button No"+i);
for (var myButtons : GameObject in buttons){
myButtons.guiTexture.pixelInset = Rect(Screen.width - buttonWidth, Screen.height - ((buttonHeight*i) + buttonHeight), buttonWidth, buttonHeight);
}
}
}
The idea with this is that I have one script for creating a toolbar of any size, rather than relating a script for each toolbar that I have to create. To make this script work I would create a number of GUI Textures, one would be the ‘Header’ if you like. This would be the parent and I would make the other buttons children of this. I would then put the script on the header object, specify the number of buttons and then ‘theoretically’ the script would space out the buttons below the header.
I want to multiply the height of the button by the variable ‘i’ which should be the arrays element value (ie [0], [1], [2] etc)
The problem is that the buttons vertical position is being multiplied by the highest value of ‘i’ rather than the value that relates to the specific array element value. The result being the header is in the correct position but the rest of the buttons are piled one on top of each other at the bottom of the toolbar. Can anyone suggest how to fix this?
If I get this working it’s really going to save me a lot of time!
Thanks