Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Random.Range calls a strange error i dont understand

Discussion in 'Scripting' started by nihondragon_unity, Sep 24, 2020.

  1. nihondragon_unity

    nihondragon_unity

    Joined:
    Sep 24, 2020
    Posts:
    2
    Hi, i have 2D Integer array and try to fill this Array with random Numbers.

    for (int row = 0; row < mapRow; row++){
    for (int column = 0; column < mapColumn; column++)
    {
    levelMap[row, column] = Random.Range[0,9];
    Debug.Log("Number " + levelMap[row, column]);
    }
    }

    I get these directly from a tutorial but, it give me an Error i dont understand.

    error CS0021: Cannot apply indexing with [] to an expression of type 'method group'

    as i know Random give back float or int, but also if i change may array to float, it gave me the same fail.
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,186
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    You have to use parentheses
    ()
    not square brackets
    []
    to invoke methods in C#.

    So
    Random.Range[0,9]
    should be
    Random.Range(0,9)
     
    Joe-Censored likes this.
  4. nihondragon_unity

    nihondragon_unity

    Joined:
    Sep 24, 2020
    Posts:
    2
    thanks, i shoud not programm if it become to late, i alwas make mistakes like this.