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

Random in C# help needed

Discussion in 'Scripting' started by Squig2, Jul 24, 2014.

  1. Squig2

    Squig2

    Joined:
    Jul 24, 2014
    Posts:
    6
    Hello, I want to spawn objects in a random position. I googled for help and I all I found is the code System.Random.Next( , ). But I don't know how to use this code, so that it gives a random value to a variable.
    I tried:

    public class Zufall : MonoBehaviour{
    void Start () { Random rnd = new Random();
    System.Random.Next(0,10);}
    void Update () {}
    }

    get the Compilerfehler CS0120 (needed Object Referenc for System.Randeom.Next()). Can anyone please help me to include the "rnd" variable in this code, so that it works?[/URL][/SIZE]
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667