So basically I get this error “cannot convert from ‘method group’ to ‘game object’”
But I absolutely have no idea why, because I do return back a GameObject, I don’t know what’s bothering Unity ![]()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bulletRandSpawn : MonoBehaviour {
public GameObject topPanel, bottomPanel, leftPanel, rightPanel, bulletGO;
void Update() {
SpawnABullet();
}
private static Vector2 RandomPointInBox(GameObject nameOfBox) {
float boxXSize = nameOfBox.GetComponent<Renderer>().bounds.size.x;
float boxYSize = nameOfBox.GetComponent<Renderer>().bounds.size.y;
Vector2 center = new Vector2(boxXSize / 2, boxYSize / 2);
return center + new Vector2(
(Random.value - 0.5f) * boxXSize,
(Random.value - 0.5f) * boxYSize
);
}
private void SpawnABullet() {
Vector2 randPoint = RandomPointInBox(randomPanelSelector);
Instantiate(bulletGO, randPoint, Quaternion.identity);
}
private GameObject randomPanelSelector() {
int randNum = Random.Range(1, 4);
switch (randNum) {
case 1:
return topPanel;
case 2:
return bottomPanel;
case 3:
return leftPanel;
case 4:
return rightPanel;
default:
return topPanel;
}
}
}