I have used C++ for a long time. Now, I just started working with C# in Unity3D. I'm almost complete at finishing an app but I can't seem to find a working int generator in Unity C# (With Min and Max values). I've tried the following:
r = Random.Range(min, max)
and
Random rand = new Random();
r = rand.next(min, max)
Both didn't work. I know in C++ you use:
r = rand() % max + min;
If you want a random number. But what is the case with Unity C#? Code:
EDIT:
using UnityEngine;
using System.Collections;
public class STarget : MonoBehaviour {
public GameObject inter;
int rand;
public GameObject TS1;
public GameObject TS2;
public GameObject TS3;
public GameObject TS4;
public GameObject TS5;
void Update () {
rand = Random.Range(1, 6);
}
public void GameRun () {
switch (rand){
case 1:
inter = TS1;
break;
case 2:
inter = TS2;
break;
case 3:
inter = TS3;
break;
case 4:
inter = TS4;
break;
case 5:
inter = TS5;
break;
}
Game.TargetSingle(inter);
}
}