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;
}
}