Switching prefabs

im looking for a way to have unity at button press switch prefabs at the same position at button press as the game is ment to have the user only have x ability after a switch that has a unique sprite

what would be the easy’st way to do this i have unity playground loaded

this is in Unity 2022.1.4f1

Ok… I’ll go out on a limb and assume you don’t know what YouTube is…

public class SwapPrefabsWithButtonPress : MonoBehaviour
{
    // click and drag the prefabs into these slots in inspector
    public GameObject prefabOneIWishToSwap;
    public GameObject prefabTwoThatDoesTheSwapping;

    void Update()
    {
         if (Input.GetKeyDown(KeyCode.space))
         { SwapThem(); }
    }

void SwapThem()
{
     if (prefabOneIWishToSwap.activeInHierarchy)
     { 
          prefabOneIWishToSwap.SetActive(false);
          prefabTwoThatDoesTheSwapping.SetActive(true);
          prefabTwoThatDoesTheSwapping.transform.position = Vector3.zero;
     }
     else
     {
          prefabOneIWishToSwap.SetActive(true);
          prefabTwoThatDoesTheSwapping.SetActive(false);
          prefabOneIWishToSwap.transform.position = Vector3.zero;
     }
}

And there you go, have fun pressing the space bar :slight_smile: