Variable in GetChild

Hey, I want to use a variable in the brackets of the geChild command, but I get the error: “Cannot implicitly convert type ‘float’ to ‘int’. An explicit conversion exist (are you missing a cast?)” Here is the Code

public int Draw = 0f;
public Transform Deck;
public Transform Drawing;

    public void Draw1()
    {
        Draw = Random.Range(0, DeckSize);
        Drawing = Deck.gameObject.transform.GetChild(Draw);
    }

Read the error. You need to remove the f. You are trying to put a float in to an int… which is exactly what that error is telling you.

1 Like

Ah thanks, now it works!