1
public int num;

void Start () {

    num = Random.Range (1, 5);

}

When I do this, the word Random gets colored red, and it just says:

"unknown resolve error".

Any ideas?

user3071284
  • 6,955
  • 6
  • 43
  • 57
zligg
  • 49
  • 2
  • 6

2 Answers2

5

Add the following code at the top of your code

using Random = UnityEngine.Random;

Random.Range is not part of System.Random, it's a Unity function

Hamix
  • 1,323
  • 7
  • 18
  • This is correct answer, if one has both `using System;` and `using UnityEngine;` the compiler cannot know which Random is meant if one just types `Random`. – wlfbck Jun 14 '17 at 10:30
0

First, make sure your script isn't named the same as unity's libraries and classes.

Since you use unity Random not System.Random, try typing the following code instead:

num = UnityEngine.Random.Range(1, 5)

You might be able to remove the UnityEngine. if you have the following statement at the top of your code:

using UnityEngine;

If you want only the Random class or want to resolve an Ambiguous reference you can use:

using Random = UnityEngine.Random;

Also if you use C#'s System.Random you can use Random.Next instead.

Tamir Vered
  • 10,187
  • 5
  • 45
  • 57