UI Button Movement Problem
Basically what i'm trying to do is move every button down that is under the pressed button so that a panel under it would show up. However, the script I have does most of that but there's a problem. Whenever i press on one button and then press on another, the buttons under the last pressed button move to the wrong position. Does anyone have a fix for this? Here's the script:
public GameObject[] buttons;
public GameObject[] exp;
public int nmbr;
public int timespressd;
public float move; // Time taken to move
bool pressed;
public float step; /// speed of movement
public void button ()
{///check how many times buton was pressed
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 0;
}
}
public void button1 ()
{
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 1;
}
}
public void button2 ()
{
if (move == 0) {
timespressd++;
pressed = true;
nmbr = 2;
move = 0.5f;
}
}
public void button3 ()
{
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 3;
}
}
public void button4 ()
{
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 4;
}
}
public void button5 ()
{
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 5;
}
}
public void button6 ()
{
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 6;
}
}
public void button7 ()
{
if (move == 0) {
timespressd++;
pressed = true;
move = 0.5f;
nmbr = 7;
}
}
void Update ()
{
if (move <= 0) {
pressed = false;
move = 0;
}
if (move > 0) {
move -= Time.deltaTime;
if (timespressd % 2 == 1) {//////go up ---- first time pressed
exp [nmbr].SetActive (true);
for (int x = nmbr; x < buttons.Length + 1; x++) {
buttons [x + 1].transform.Translate (Vector2.up * -step * Time.deltaTime * 2);
}
}
if (timespressd % 2 == 0) {////////go down,even number
exp [nmbr].SetActive (false);
for (int x = nmbr; x < buttons.Length + 1; x++) {
buttons [x + 1].transform.Translate (Vector2.up * step * Time.deltaTime * 2);
}
}
}
}
Comment