Object moving problem
I am trying to move objects in array up or down for a certain amount of time when a button is pressed. This seems so simple however it does not work and I have tried many different ways to do it. Can anyone help? Here is the script:
public GameObject[] buttons; public Button[] panels; public GameObject[] exp; public int nmbr; public int timespressd; public float move; bool pressed; public Transform there; public Transform thereup; public float step;
public void button ()
{
timespressd ++;///check how many times button was pressed
pressed = true;
nmbr = 0;
move = 0;
}
public void button1 ()
{
timespressd ++;
pressed = true;
nmbr = 1;
move = 0;
}
public void button2 ()
{
timespressd ++;
pressed = true;
nmbr = 2;
move = 0;
}
public void button3 ()
{
timespressd ++;
pressed = true;
nmbr = 3;
move = 0;
}
void Update ()
{
if (pressed == true) {
move += Time.deltaTime;
if(move > 0.3f){//when the objects should stop movng
pressed = false;
}
if (nmbr == 0 && timespressd % 2 == 0) {
buttons [1].transform.position = Vector3.MoveTowards (transform.position, there.position, step * Time.deltaTime);
buttons[2].transform.position = Vector3.MoveTowards(transform.position,there.position,step* Time.deltaTime);
buttons[3].transform.position = Vector3.MoveTowards(transform.position,there.position,step* Time.deltaTime);
}
if (nmbr == 0 && timespressd % 2 == 1) {
buttons [1].transform.position = Vector3.Lerp (transform.position, thereup.position, step * Time.deltaTime);
buttons[2].transform.position = Vector3.MoveTowards(transform.position,thereup.position,step* Time.deltaTime);
buttons[3].transform.position = Vector3.MoveTowards(transform.position,thereup.position,step* Time.deltaTime);
}
}
}
}
Your answer
Follow this Question
Related Questions
Lerp on the every 3 * n cycle does some wierd thing. 0 Answers
Quaternion lerp slowing down movement? 1 Answer
hi everyone how can i move an object from a point to specific point(point b) by mouse click 0 Answers
Vector2.MoveTowards Not Working 1 Answer
How To Duplicate Canvas To Follow Player 0 Answers