Hello guys,
I am new to Unity and learn with some tutorials from YouTube but now I got the error CS0104 and I dont know what I should do. The error is in every line with “Random.Range”. Here is my skript I hope you can help me
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Threading;
using UnityEngine;
public class obstacle_spawnen : MonoBehaviour
{
public GameObject[ ] obstacles;
public List obstaclesToSpawn = new List();
int index;
void Awake()
{
InitObstacles();
}
void Start()
{
StartCoroutine(SpawnObstacles());
}
void InitObstacles()
{
index = 0;
for (int i = 0; i < obstacles.Length; i++)
{
GameObject obj = Instantiate(obstacles[index], transform.position, Quaternion.identity);
obstaclesToSpawn.Add(obj);
obstaclesToSpawn*.SetActive(false);*
index++;
if (index == obstacles.Length)
{
index = 0;
}
}
}
IEnumerator SpawnObstacles()
{
yield return new WaitForSeconds(Random.Range(1.5, 4.5f));
int index = Random.Range(0, obstaclesToSpawn);
while (true)
{
if (!obstaclesToSpawn[index].activeInHierarchy)
{
obstaclesToSpawn[index].SetActive(true);
break;
}
else
{
index = Random.Range(0, obstaclesToSpawn);
}
}
StartCoroutine(SpawnObstacles());
}
}