Hey guys! I’m working on card game, and I totally lost my mind with prefab. The code bellow works, but makes CardPrefab independant object. I want it to be child of let’s say Hand GameObject, because I want to store cards in hand
Any idea how to fix it? I went through some threads where this was already asked, but it didn’t work for me… I must be doing something wrong.
public class MakeMeACard : MonoBehaviour {
public Transform CardPrefab;
public Transform HandGo;
void Start () {
GameObject go = Instantiate(CardPrefab, new Vector3(400, -85, 4), Quaternion.identity) as GameObject;
go.parent = HandGo;
Debug.Log("Card made!");
}
}
obviously youll need to link the transform of HandGo to your parent object
Just use the code @ThermalFusion gave you, which should work fine. Instead of hand, put your Hand object reference, or drag Hand object into hand property from the MakeMeACard object in unity editor