Can anyone help me with this the exact error is this

Assets\Challenge 4\Scripts\SpawnManagerX.cs(30,40): error CS0246: The type or namespace name ‘Enemy’ could not be found (are you missing a using directive or an assembly reference?)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManagerX : MonoBehaviour
{
public GameObject enemyPrefab;
public GameObject powerupPrefab;

private float spawnRangeX = 10;
private float spawnZMin = 15; // set min spawn Z
private float spawnZMax = 25; // set max spawn Z
public float enemySpeed = 50;

public int enemyCount;
public int waveNumber = 1;

public GameObject player;

void Start()
{
SpawnEnemyWave(waveNumber);
SpawnPowerup(waveNumber);
}

// Update is called once per frame
void Update()
{
enemyCount = FindObjectsOfType().Length; // 30 line

if (enemyCount == 0)
{
waveNumber++;
SpawnEnemyWave(waveNumber);
SpawnPowerup(waveNumber);
}

}

// Generate random spawn position for powerups and enemy balls
Vector3 GenerateSpawnPosition ()
{
float xPos = Random.Range(-spawnRangeX, spawnRangeX);
float zPos = Random.Range(spawnZMin, spawnZMax);
Vector3 randomPos = new Vector3(xPos, 0, zPos);
return randomPos;
}

void SpawnEnemyWave(int enemiesToSpawn)
{

// Spawn number of enemy balls based on wave number
for (int i = 0; i < enemiesToSpawn; i++)
{
Instantiate(enemyPrefab, GenerateSpawnPosition(), enemyPrefab.transform.rotation);
}

waveNumber++;
enemyCount += 25;
ResetPlayerPosition(); // put player back at start

}

// Move player back to position in front of own goal
void ResetPlayerPosition ()
{
player.transform.position = new Vector3(0, 1, -7);
player.GetComponent().velocity = Vector3.zero;
player.GetComponent().angularVelocity = Vector3.zero;

}

void SpawnPowerup(int powerupsToSpawn)
{
Instantiate(powerupPrefab, GenerateSpawnPosition(), powerupPrefab.transform.rotation);

if (GameObject.FindGameObjectsWithTag(“Powerup”).Length == 0) // check that there are zero powerups
{
Instantiate(powerupPrefab, GenerateSpawnPosition() , powerupPrefab.transform.rotation);

}
}

}

You don’t have a script called Enemy. You need to have such a script to call FindObjectsOfType<Enemy>().

1 Like

Thanks!

Also, please use Code tags next time :slight_smile: They will make your code in the forum easier to read - example:

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
    }
  }
}

(Source: shamelessly stolen from w3schools)

.

1 Like