Search code examples
c#unityscriptunity-game-engine

Why the property Range not exist in Random class in unity?


using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.ThirdPerson;

public class Multiple_objects : MonoBehaviour {

    public GameObject prefab;
    public GameObject[] gos;
    public int NumberOfObjects;
    private ThirdPersonCharacter[] thirdPersonCharacter;
    private Animator[] _animator;
    private int count = 0;

    void Awake()
    {
        Vector3 v3 = prefab.transform.position;
        _animator = new Animator[NumberOfObjects];
            gos = new GameObject[NumberOfObjects];
        for(int i = 0; i < gos.Length; i++)
        {
            count = count + 2;
            GameObject clone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);
            gos [i] = clone;
            gos [i].transform.position = new Vector3 (v3.x - count, v3.y, v3.z);
            _animator [i] = gos[i].GetComponent<Animator> ();
            Math.Round(Random

When i type point after the Random like: Random. I have only Equals and ReferenceEquals

And if i create a variable of Random for example:

Random _random;

Then i type _random. I get more propeties but not Range.


Solution

  • You are using both the UnityEngine and System namespace. Both of these namespaces contain a Random class, so Visual Studio/Unity doesn't know which one you want to use. To specify which random you want to use, you would simply do this:

    UnityEngine.Random.Range(0.0f, 5.0f);