I need help with this code. I want to spawn a object (ball) on a spawnpoint. I placed the ball at prefabs folder and turn the ball off, but for some reason the clone balls won’t turn on when they spawn. What am i doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnAtPointScript : MonoBehaviour
{
public GameObject ball;
public Transform spawnPoint;
public float maxX;
public float maxZ;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnBall", 1f, 3f);
}
// Update is called once per frame
void Update()
{
}
void SpawnBall()
{
float randomX = Random.Range(-maxX, maxX);
float randomZ = Random.Range(-maxZ, maxZ);
Vector3 randomSpawnPos = new Vector3(randomX, 10f, randomZ);
Instantiate(ball, randomSpawnPos, Quaternion.identity);
}
}