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" and said: '"Random" ist ein mehrdeutiger Verweis zwischen "UnityEngine.Random" und "System.Random". Assembly-CSharp C:\Users\phili\Unity Projekte\Jumpy Runner\Assets\scripts\obstacle_spawnen.cs Here is my skript I hope you can help me Code (CSharp): 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<GameObject> obstaclesToSpawn = new List<GameObject>(); 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.5f, 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()); } }
Please use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/ How to report problems productively in the Unity3D forums: http://plbm.com/?p=220 Help us to help you.
For each instance of "Random", type "UnityEngine.Random", e.g. "UnityEngine.Random.Range(....." That will make the reference not ambiguous between the two possible "Random" classes.
Thanks for the clue but I tried this before and than come the error CS1503 Argument "2": Konvertierung von "System.Collections.Generic.List<UnityEngine.GameObject>" in "float" nicht möglich. Assembly-CSharp C:\Users\phili\Unity Projekte\Jumpy Runner\Assets\scripts\obstacle_spawnen.cs for the last two Random.Range() ´s. Maybe you can help me of this too. Code (CSharp): 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<GameObject> obstaclesToSpawn = new List<GameObject>(); 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[i].SetActive(false); index++; if (index == obstacles.Length) { index = 0; } } } IEnumerator SpawnObstacles() { yield return new WaitForSeconds(UnityEngine.Random.Range(1.5f, 4.5f)); int index = UnityEngine.Random.Range(0, obstaclesToSpawn); while (true) { if (!obstaclesToSpawn[index].activeInHierarchy) { obstaclesToSpawn[index].SetActive(true); break; } else { index = UnityEngine.Random.Range(0, obstaclesToSpawn); } } StartCoroutine(SpawnObstacles()); } }
index = UnityEngine.Random.Range(0, obstaclesToSpawn); should be index = UnityEngine.Random.Range(0, obstaclesToSpawn.Count); because you want the number of elements in the list, not the list itself.