using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject enemyPrefab;
private float spawnRange = 9.0f;
// Start is called before the first frame update
void Start()
{
Instantiate(enemyPrefab, GenerateSpawnPosition, enemyPrefab.transform.rotation);
}
// Update is called once per frame
private Vector3 GenerateSpawnPosition ()
{
float spawnPosX = Random.Range(-spawnRange, spawnRange);
float spawnPosZ = Random.Range(-spawnRange, spawnRange);
Vector3 randomPos = new Vector3(spawnPosX, 0, spawnPosZ);
return randomPos;
}
}
It says "error CS1503: Argument 2: cannot convert from ‘method group’ to ‘Vector 3’
Line 13 is a call to Instantiate. As you can see from the docs here:
It has a few forms. Your script (I believe) is trying to use the fourth one down, and I base that on what you are passing as arguments.
The problem comes with the second argument. You are passingGenerateSpawnPosition as the argument, but that’s the actual function. What you want is to CALL the function, which is done by suffixing it with parentheses: GenerateSpawnPosition(), and then pass in the result of that function call, which is a Vector3, the position.
That’s why it is complaining that it can’t change method group to Vector3!
All that said, line 13 should compile if it reads: