[Solved] Change sprites depending on value?

Well, I have this lil’ player, and he can be type 1 (A black suit) and type 2 (A green suit), I dont know why my code does not work. Does the Generic Sytem Collection has to do with this? because I am using it, and I think my problem has to do with it.

    public Sprite BSuit; //Black Suit sprite
    public Sprite GSuit; //Green Suit sprite
    private SpriteRenderer RendererOSprites; //Sprite Renderer Component
    private int Type; //Type variable

    void Start()
    {
        Type = Random.Range(1, 3); // Player does not choose the color of the suit
        Debug.Log("" + Type);            // Just to see what was chosen
        RendererOSprites = GetComponent<SpriteRenderer>(); //Set the Renderer O' Sprites to the SpriteRenderer
        if (Type == 1)
        { RendererOSprites.sprite = BSuit; }  //Set Black suit if type is 1
        if (Type == 2)
        { RendererOSprites.sprite = GSuit; } //Set Green Suit if type is 2
    }

By default, in the editor, I set the sprite renderer to have BSuit sprite, and it never changes, the Debug Log shows correctly numbers 1 or 2 upon startup, but the sprite does not change, also if I remove the sprites of the SpriteRenderer in the editor, it never aquires a sprite.

Plz help

I would be very surprised if you did get a number 2 from that code. Random.Range excludes the upper bounds when dealing with integers. So your code should return a number between 1 and 1.

I think if you try Random.Range(1,3) you will get what your looking for (a number that is 1 or 2).

o lol, sorry 2 is too close from 3 in the keyboard xD, let me edit it, I kinda didnt copy + pasted

It’d probably be smarter to use an array for the list of sprites, and a switch statement for the sprite picker.

Try using a float, by the way. Then round the float to an integer (Mathf.RoundToInt or Mathf.FloorToInt)

Yo how’s that made?
Im not experienced yet, started a week ago xD

How’s what made, an array or a switch statement?

If you don’t know what one or the other is, you should take the C# course by SoloLearn. It’s a very understandable course, you’d like it.

If you don’t have the time to do that then I’ll explain for you if you wish :smile: