Teleport Objects to original position
After a game is over, I want to have a reset button.
I have 25 buttons all beeing in the wrong position, so I thought of storing the original pos in a 25 for loop and then teleporting erevy button to it(the stored pos) with another for in the reset button.
The problem is, that most questions to this topic are for 3d vectors and games and my game is 2d. (note: the buttons are in arrays so you could use like: Buttons[i].position = storedpos.x.y.z
I also think that I can't use playerprefs, the buttons are simple "public Buttons[]"
please help, I am stuck for over 2h now
Answer by BetaFruit · Jan 06 at 12:46 PM
Does every button have a script? If so in the button script save the startposition in it. Then when the reset button is pushed set a bool like reset active in a static script.
static script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mystaticscript
{
public static bool reset;
}
button script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class button : MonoBehaviour
{
public Vector2 startpos;
void Start()
{
startpos = transform.localPosition;
}
void Update()
{
if (mystaticscript.reset == true)
{
transform.localposition = startpos;
}
}
}