Random.Range doesn't work
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class ChallengeController : MonoBehaviour {
public float scrollSpeed = 5.0f; //brzina micanja
public GameObject[] challenges;
public float frequency = 0.5f;
float counter = 0.0f;
public Transform challengesSpawnPoint;
// Use this for initialization
void Start () {
GenerateRandomChallenge();
}
// Update is called once per frame
void Update () {
//generiranje objekata
if(counter <= 0.0f)
{
GenerateRandomChallenge();
}
else
{
counter -= Time.deltaTime * frequency;
}
//Scrolling
GameObject currentChild;
for (int i = 0; i < transform.childCount; i++)
{
currentChild = transform.GetChild(i).gameObject;
ScrollChallenge(currentChild);
if (currentChild.transform.position.x <= -15.0f) //da unistimo sto je sve previuse iza nas
{
Destroy(currentChild);
}
}
}
void ScrollChallenge (GameObject currentChallenge)
{
currentChallenge.transform.position -= Vector3.right * (scrollSpeed * Time.deltaTime); //pomicanje ekrana u desno
}
void GenerateRandomChallenge()
{
Instantiate(challenges[(Random.Range(0 , challenges.Length)], challengesSpawnPoint.position, Quaternion.identity); //here it says that the nested type 'Range' does not exist in the type 'UnityEngine.Random'
counter = 1.0f;
}
}
Answer by FlammusLucis · Jun 09, 2017 at 03:41 PM
It looks like you aren't using the "Random" library. See at the top where it says:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
you need to add:
using Random = UnityEngine.Random;
That will make it so that when you use the "Random.Range" it knows where the code you are trying to get to is.
p.s, you can find a lot of information about random stuff in this unity tutorial on making a rougelike.
I hope that helps, and good luck with your game.
Answer by bakedpizaa · May 24 at 09:24 AM
In my case Range = Random.Range(minRange, maxRange);
There is values in min max range .... For example 4 and 8 When I start playing the range is fixed ..... It is not updating to different random Range after ..... Actually I want to make like .... It takes random range Evey time I think it is hard to explain but pls tell if you understand