this is my code so far, but i want the buttons to stop at the position so it form a square. the final positions are, set behind ButtonLeft… etc.
How the tackle this problem?
var iconLB : Texture2D;
var iconLO : Texture2D;
var iconRB : Texture2D;
var iconRO : Texture2D;
var myStyle : GUIStyle;
var isDaySkybox : boolean = true;
var dayMaterial : Material;
var nightMaterial : Material;
var isFullScreen : boolean = true;
var isWalking : boolean = true;
var iconR : Texture2D;
var isBeginScript : boolean = true;
var isBeginMenu : boolean = false;
private var guiAlpha : float;
var ButtonLeftB = -25.0; // 10.0
var ButtonLeftH = -25.0; // 10.0
var ButtonRightB = 105.0; // 70.0
var ButtonRightH = -25.0; // 10.0
var ButtonDownLeftB = -25.0; // 10.0
var ButtonDownLeftH = 105.0; // 70.0
var ButtonDownRightB = 105.0; // 70.0
var ButtonDownRightH = 105.0; // 70.0
function Start()
{
yield GUIFade(0,1,2);
myStyle = new GUIStyle();
// Camera.main.GetComponent(Skybox).material=nightMaterial;
}
function Update()
{
ButtonLeftB += (Time.deltaTime * 10.0);
ButtonLeftH += (Time.deltaTime * 10.0);
ButtonRightB -= (Time.deltaTime * 10.0);
ButtonRightH += (Time.deltaTime * 10.0);
ButtonDownLeftB += (Time.deltaTime * 10.0);
ButtonDownLeftH -= (Time.deltaTime * 10.0);
ButtonDownRightB -= (Time.deltaTime * 10.0);
ButtonDownRightH -= (Time.deltaTime * 10.0);
}
function OnGUI ()
{
GUI.color.a = guiAlpha;
if(GUI.Button(Rect(62,62,16,16), iconR,myStyle))
{
isBeginScript = !isBeginScript;
if(!isBeginScript)
isBeginMenu = !isBeginMenu;
Debug.Log("Menu open");
GUIFade(0,1,3);
Debug.Log("fade beginmenu");
}
if(isBeginMenu)
{
if (GUI.Button(Rect(ButtonLeftB,ButtonLeftH,60,60), iconLB,myStyle))
{
isDaySkybox = !isDaySkybox;
if (!isDaySkybox)
Camera.main.GetComponent(Skybox).material=dayMaterial;
else
Camera.main.GetComponent(Skybox).material=nightMaterial;
Debug.Log("upper left, Day-Night");
}
if(GUI.Button(Rect(ButtonDownLeftB,ButtonDownLeftH,60,60), iconLO,myStyle))
{
isFullScreen = !isFullScreen;
if(isFullScreen)
Screen.SetResolution(640,480, false, 60);
else
Screen.SetResolution(640,480, true, 60);
Debug.Log("Down left, Full-Normale Screen");
}
if(GUI.Button(Rect(ButtonRightB,ButtonRightH,60,60), iconRB,myStyle))
{
isWalking = !isWalking;
if(!isWalking)
{
Destroy (GetComponent("FPSWalker"));
Destroy (GetComponent(CharacterController));
gameObject.AddComponent("BoxCollider");
}
else
{
gameObject.AddComponent("FPSWalker");
Destroy(GetComponent(BoxCollider));
}
Debug.Log("upper right, Walk-Fly");
}
if(GUI.Button(Rect(ButtonDownRightB,ButtonDownRightH,60,60), iconRO,myStyle))
{
if(!isBeginMenu);
isBeginMenu = !isBeginMenu;
isBeginScript = !isBeginScript;
Debug.Log("down right");
}
}
}
function GUIFade (start : float, end : float, length : float) {
for (i = 0.0; i <= 1.0; i += Time.deltaTime*(1/length)) {
guiAlpha = Mathf.Lerp(start, end, i);
yield;
Debug.Log("Menu alpha");
}
guiAlpha = end; // Accounts for Time.deltaTime variance
}