Hi, I’m following the bonus tutorials (PDF linked below) for the Prototype 2 project and I’m trying to get the animals to spawn left and right. I’ve written the code out as I’ve tried to understand it, but the two new methods do not seem to be working. Visual Studio is reporting that the two methods are unused members, however. They were typed as the example showed in the pdf document linked. What am I doing wrong here?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject[] animalPrefabs;
private float spawnRangeX = 20;
private float spawnPosZ = 20;
private float startDelay = 2;
private float spawnInterval = 1.5f;
public float sideSpawnMinZ;
public float sideSpawnMaxZ;
public float sideSpawnX;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnRandomAnimal", startDelay, spawnInterval);
}
// Update is called once per frame
void Update()
{
}
// Spawns animal at random location
void SpawnRandomAnimal()
{
Vector3 spawnPos = new Vector3(Random.Range(-spawnRangeX, spawnRangeX), 0, spawnPosZ);
int animalIndex = Random.Range(0, animalPrefabs.Length);
Instantiate(animalPrefabs[animalIndex], spawnPos, animalPrefabs[animalIndex].transform.rotation);
}
void SpawnLeftAnimal()
{
int animalIndex = Random.Range(0, animalPrefabs.Length);
Vector3 spawnPos = new Vector3(-sideSpawnX, 0, Random.Range(sideSpawnMinZ, sideSpawnMaxZ));
Vector3 rotation = new Vector3(0, 90, 0);
Instantiate(animalPrefabs[animalIndex], spawnPos, Quaternion.Euler(rotation));
}
void SpawnRightAnimal()
{
int animalIndex = Random.Range(0, animalPrefabs.Length);
Vector3 spawnPos = new Vector3(sideSpawnX, 0, Random.Range(sideSpawnMinZ, sideSpawnMaxZ));
Vector3 rotation = new Vector3(0, -90, 0);
Instantiate(animalPrefabs[animalIndex], spawnPos, Quaternion.Euler(rotation));
}
}
Thank you very much for anyone that can assist.