- Home /
Question by
RichCoggin · Aug 14, 2013 at 11:22 AM ·
guibuttonsitween
Stuck with sliding GUI panels
Hi there,
I have 2 GUI panels in my scene. What I'm trying to do is have the first panel move off of screen to the right and then bring in the second one in from the left to the same position as the first. At present I have coded the two Panels, but not sure what action to add to the first button to bring in the second panel and where it should go in the code.
Ideally, I would also like the 2nd panel to move off of screen as well when a button is clicked (like the first panel).
p.s. using iTween
Any help with understanding this would be great. Here's my code so far:
using UnityEngine;
using System.Collections;
public class IntroPanels : MonoBehaviour
{
//LeftNav GUI skin reference
public GUISkin IntroPanels1;
//Panel 2 MenuRect2 = The panel 2. Box2 rect = the button
public bool menu2RectState = false;
public bool box2RectState = false;
//Panel
public Rect menu2Rect = new Rect(-1000,184,600,400); //MENU PANEL
public Rect initialPositionMenu2 = new Rect(-1000,184,600,400); //MENU PANEL
public Rect activePositionMenu2 = new Rect(212,184,600,400); //MENU PANEL
//Button
public Rect box2Rect = new Rect(235,280,120,50); //MENU BUTTON
public Rect initialPositionbox2 = new Rect(235,280,120,30); //MENU BUTTON
public Rect activePositionbox2 = new Rect(235,280,120,50);//MENU BUTTON
////
//Panel 1 Menu1Rect = The panel. Boxrect = the button
public bool menu1RectState = false;
public bool boxRectState = false;
//Panel
public Rect menu1Rect = new Rect(212,184,600,400); //MENU PANEL
public Rect initialPositionMenu = new Rect(212,184,600,400); //MENU PANEL
public Rect activePositionMenu = new Rect(1200,184,600,400); //MENU PANEL
//Button
public Rect boxRect = new Rect(235,280,120,50); //MENU BUTTON
public Rect initialPosition = new Rect(235,280,120,30); //MENU BUTTON
public Rect activePosition = new Rect(235,280,120,50);//MENU BUTTON
////
//AUDIO
public AudioClip PlanetMenuSound;
void OnGUI()
{
//GUISkin for Group
GUI.skin = IntroPanels1;
////////////////Panel2
GUI.BeginGroup(menu2Rect, "","Panel2");
if(GUI.Button(box2Rect,"","Panel2Button"))
{
audio.PlayOneShot(PlanetMenuSound);
if(menu2RectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",menu2Rect,"to",initialPositionMenu,"onupdate","MoveMenu2","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",menu2Rect,"to",activePositionMenu,"onupdate","MoveMenu2","easetype","easeinoutback"));
}
menu2RectState = !menu2RectState;
if(boxRectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",box2Rect,"to",initialPosition,"onupdate","Movebox2","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",box2Rect,"to",activePosition,"onupdate","Movebox2","easetype","easeinoutback"));
}
box2RectState = !box2RectState;
}
GUI.EndGroup();
////////////////Panel1
GUI.BeginGroup(menu1Rect, "","Panel1");
if(GUI.Button(boxRect,"","Panel1Button"))
{
audio.PlayOneShot(PlanetMenuSound);
if(menu1RectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",menu1Rect,"to",initialPositionMenu,"onupdate","MoveMenu1","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",menu1Rect,"to",activePositionMenu,"onupdate","MoveMenu1","easetype","easeinoutback"));
}
menu1RectState = !menu1RectState;
if(boxRectState)
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",initialPosition,"onupdate","Movebox","easetype","easeinoutback"));
}
else
{
iTween.ValueTo(gameObject,iTween.Hash("from",boxRect,"to",activePosition,"onupdate","Movebox","easetype","easeinoutback"));
}
boxRectState = !boxRectState;
}
GUI.EndGroup();
}
//Panel 2
void MoveMenu2 (Rect newCoordinates){
menu2Rect=newCoordinates;
}
void MoveBox2 (Rect newCoordinates){
box2Rect=newCoordinates;
}
//Panel 1
void MoveMenu1 (Rect newCoordinates){
menu1Rect=newCoordinates;
}
void MoveBox (Rect newCoordinates){
boxRect=newCoordinates;
}
}
Comment