asked 216k views
5 votes
1. Public Gameobject [ ] enemyPrefabs;

2.
3. void start ()
4. {
5. instantiate (enemyPrefabs)
6. }
The code below creates an error that says, "error CS1503: Argument 1: cannot convert from 'UnityEngine.GameObject[]' to 'UnityEngine.Object'". What could you do to remove the errors?
a) On line 5, change "enemyPrefabs" to "GameObject"
b) On line 1, change "enemyPrefabs" to "enemyPrefabs[0]"
c) On line 3, change "Start()" to "Update()"
d) On line 5, change "enemyPrefabs" to "enemyPrefabs[0]"

asked
User KCK
by
8.3k points

1 Answer

3 votes

Final answer:

The error can be fixed by instantiating a specific element from the array enemyPrefabs. Change line 5 to instantiate (enemyPrefabs[0]) to instantiate the first element in the array.

Step-by-step explanation:

The error message you are encountering is due to the Instantiate function requiring a single GameObject instance, but you are passing it an array of GameObjects. The correct way to fix this error is to specify which element in the array you want to instantiate. This can be done by providing the index of the specific element you want to instantiate inside the array enemyPrefabs.

To fix the error, change the code on line 5 from instantiate (enemyPrefabs) to instantiate (enemyPrefabs[0]). This will instantiate the first element in the enemyPrefabs array.

answered
User Janelle
by
8.1k points