Can't convert GameObject to GameObject[]
The code seems not to be working with Unity5:
private AudioSource[] sirens;
In the void Awake function:
GameObject[] sirenGameObjects = GameObject.FindGameObjectsWithTag(Tags.siren);
sirens = new AudioSource[sirenGameObjects.Length];
Any advice on solving this problem will be appreciated, It is bugging me for an hour now and I have no clue how to solve it.
Thank you in advance! +1337
Answer by mikelortega · Apr 06, 2016 at 08:17 AM
The problem in your code is that FindGameObjectsWithTag expects a string:
GameObject[] sirenGameObjects = GameObject.FindGameObjectsWithTag("siren");
I cannot see any problems with arrays in your code.
Your answer
Follow this Question
Related Questions
ERROR CS0029: Cannot implicitly convert type `UnityEngine.GameObject' to `TriggerSphere' 1 Answer
Cannot convert 'UnityEngine.Quaternion' expression to type 'bool' 1 Answer
[SOLVED]How do I spawn GameObject[] in Transform[]? 2 Answers
[Unity2d Sprite Rendering Question] Grabbing and altering the sprite renderer of another game object 0 Answers
How do I track the initial direction of a Non Rigidbody gameobject in 2D? 1 Answer