Question by
RoyalDio2 · Dec 11, 2020 at 10:57 AM ·
c#gameobjectscript.list
How To Find GameObject From List And Add To Player List
I Try To Add Card gameobject With CardID To Player Card List. From Card Data
i try to use this But I Don't Inderstend The Problem Sorry For Bad Eng
int index = GameManager.GetComponent<CardData>().cardPack1.Find(obj => obj.ID == Card1ID);
// Yes
if (index >= 0)
{
GameObject o = GameManager.GetComponent<CardData>().cardPack1[index].HitPrefab;
}
Player Script
Player
public GameObject GameManager;
public int Card1ID= 0;// Get This Card By ID
public int Card2ID= 0;// Get This Card By ID
public int Card3ID= 0;// Get This Card By ID
public List<GameObject> CardDeckList = new List<GameObject>();
void Start()
{
GameManager = GameObject.Find("GameManager");
for (int i = 0; i < GameManager.GetComponent<CardData>().cardPack1.Count; i++)
{
if (GameManager.GetComponent<CardData>().cardPack1[i].ID == 2)
{
// Add This Card To Player List } } }
=======================================
Card Data Script
CardData
public List<CardPack1> cardPack1 = new List<CardPack1>();
[System.Serializable]
public class CardPack1
{
public string CardName;// Card Name
public string Type;// Warrior, Mage,
public string Info;// Card Information
public Sprite CardIcon;// Card Image
public GameObject CardPrefab;
}
Comment
Your answer
Follow this Question
Related Questions
What range of values need to be inserted if we need to pull a random item from the list? 0 Answers
Edit properties of certain list items,Changing properties of objects in a list (c#) 1 Answer
Unity C# how to Foreach variable in Model/Contract 0 Answers