- Home /
This question was
closed Feb 08, 2019 at 05:29 PM by
AbubakrKhan for the following reason:
Other
Question by
AbubakrKhan · Feb 03, 2019 at 02:29 AM ·
c#unity 5objectsprefab-instance
Hi I am trying to assign gameobject (prefab) from the List to another prefab gameobject but i think there is some mistake in one line of my code Please help.
Here is the Code
public static CharacterShop characterShop;
public List<Character> characterList = new List<Character>();
public GameObject SkinHolderPrefab;
public Transform grid;
void FillList()
{
for(int i=0; i<characterList.Count; i++)
{
GameObject holder = Instantiate(SkinHolderPrefab,grid);
//passing data to skinholderscrip
SkinHolder holderScript = holder.GetComponent<SkinHolder>();
holderScript.skinName.text = characterList[i].characterName;
holderScript.skinPrice.text = characterList[i].characterPrice.ToString();
holderScript.skinID = characterList[i].characterID;
holderScript.skin = characterList[i].character;
}
}
this above line is not assigning the character prefab (gameobject) from the list to skin prefab (gameobject). Inshort its not working but its not showing any error either. below is the rest of the 3 classes linked with this script. Any help would be appreciated. Thanks in advance.holderScript.skin = characterList[i].character;
public class SkinHolder : MonoBehaviour {
public Text skinName;
public Text skinPrice;
public int skinID;
public GameObject skin;
public GameObject buyButton;
}
[System.Serializable] public class Character{
public string characterName;
public int characterID;
public int characterPrice;
public GameObject character;
public bool bought;
}
Comment
Best Answer
Answer by pako · Feb 03, 2019 at 09:44 AM
Try setting the result of Instantiate
to holderScript.skin
:
holderScript.skin = Instantiate<GameObject>(characterList[i].character);
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to check if Trigger was touched or clicked? 1 Answer
Input stays the same no matter the rotation ? 0 Answers
Google Daydream Thread with Unity 1 Answer