'I'm trying to use a button trigger to move multiple gameobjects to and from their original transform positions to a single point
I'm making an inventory system and want to use a button to move all items from under the button to a grid (which is their original transform coordinates). want to reference the coordinate to the original game object through their index, but it does not move at all. I'm not sure if the lists I have set up have nothing indexed, or the translation isn't working. what can I correct here to make this work?
public class BaseInventory : MonoBehaviour
{
public List<GameObject> myObjects;
public Vector3 rootV3;
public float delayBetweenObjects = .1f;
public float animationDuration = .1f;
public List<Vector3> baseV3 = new List<Vector3>();
public Vector3 endV3;
void SavePositions()
{
foreach(GameObject g in myObjects)
{
baseV3.Add(g.transform.position);
}
}
private void Awake()
{
Hide();
}
private void Hide()
{
foreach (GameObject g in myObjects)
{
g.SetActive(false);
}
}
public void ShowItems()
{
StartCoroutine(Show());
}
IEnumerator Show()
{
foreach (GameObject g in myObjects)
{
int i = myObjects.IndexOf(g);
endV3 = baseV3[i];
yield return new WaitForSeconds(delayBetweenObjects);
g.SetActive(true);
g.transform.DOMove(endV3, animationDuration).From();
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|