Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Generate Random Number when using System

Discussion in 'Scripting' started by The_Fantaz, May 6, 2021.

  1. The_Fantaz

    The_Fantaz

    Joined:
    Aug 8, 2020
    Posts:
    16
    I want to use Math.Abs in my script, while also generating a number. However, trying to use Random.Range() gives me an error since it interferes with the System that I imported.

    How could I solve this?
     
  2. ShiftyGames

    ShiftyGames

    Joined:
    Sep 10, 2018
    Posts:
    16
    Both UnityEngine and System have a Random function. You need to specify which one you want to use. E.g. UnityEngine.Random or System.Random
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,913
    If you need the UnityEngine Random, just put this in the top of the file:
    using Random=UnityEngine.Random;