jeudi 30 mars 2017

C#: I need to input a value, and extract information of an object

I'm programming in Unity, using the language C#.

I need to be able to input a random value, search through a list of objects in a class, and find the one with an ID that matches the random value. To make things more complicated, I also have to extract all information I can on that item. I have the random input, which is the following line of code:

firstCard = Random.Range (1, 18);

Then I have the cards:

public class Card {
public int CardID;
public string element;
public int value;
public string color;

public Card (int cardids, string elementals, int values, string coloring) {
    this.CardID = cardids;
    this.element = elementals;
    this.value = values;
    this.color = coloring;
    }
}

public class CardList : MonoBehaviour {
    public Card a = new Card(1,"Fire",3,"Blue");
    //Other cards appear here.
}

So if the random number returns 1, I want it to retun "Fire", 3, and "Blue" because the CardID matches the random number. These two groups of code are in two different files, if that changes anything.




Aucun commentaire:

Enregistrer un commentaire