I have been learning c# for a while now, but im stuck for two days with this error:
‘Assets\Scripts\SpawnManager.cs(32,13): error CS0106: The modifier ‘public’ is not valid for this item’
Havent found any solution online, can someone please help? Gonna post the code below
PLAYER SCRIPT:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]
private float _speed = 3.5f;
[SerializeField]
private GameObject _laserPrefab;
[SerializeField]
private float _fireRate = 0.5f;
private float _canFire = -1f;
[SerializeField]
private int _Lives = 3;
private SpawnManager _spawnManager;
void Start()
{
transform.position = new Vector3(0, 0, 0);
_spawnManger = GameObject.Find(“Spawn_Manager”).GetComponent();
if (_spawnManager == null)
{
Debug.LogError(“The spawn manager is NULL.”);
}
}
void Update()
{
calculateMovement();
if (Input.GetKeyDown(KeyCode.Space) && Time.time > _canFire)
{
FireLaser();
}
}
void calculateMovement()
{
float horizontalInput = Input.GetAxis(“Horizontal”);
transform.Translate(Vector3.right * horizontalInput * _speed * Time.deltaTime);
float verticallInput = Input.GetAxis(“Vertical”);
transform.Translate(Vector3.up * verticallInput * _speed * Time.deltaTime);
if (transform.position.y >= 5.2f)
{
transform.position = new Vector3(transform.position.x, -4.6f, 0);
}
else if (transform.position.y <= -4.6f)
{
transform.position = new Vector3(transform.position.x, 5.2f, 0);
}
if (transform.position.x >= 9.6f)
{
transform.position = new Vector3(-9.6f, transform.position.y, 0);
}
else if (transform.position.x <= -9.6f)
{
transform.position = new Vector3(9.6f, transform.position.y, 0);
}
}
void FireLaser()
{
_canFire = Time.time + _fireRate;
Instantiate(_laserPrefab, new Vector3(transform.position.x, transform.position.y + 0.8f, 0), Quaternion.identity);
}
public void Damage()
{
_Lives–;
if (_Lives < 1)
{
_spawnManager.OnPlayerDeath();
Destroy(this.gameObject);
}
}
}
SPAWN MANAGER SCRIPT:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
[SerializeField]
private GameObject _enemyPrefab;
[SerializeField]
private GameObject _enemyContainer;
private bool _stopSpawning = false;
void Start()
{
StartCoroutine(SpawnRoutine());
}
void Update()
{
}
IEnumerator SpawnRoutine()
{
while (_stopSpawning == false)
{
Vector3 posToSpawn = new Vector3(Random.Range(-9.2f, 9.2f), 7, 0);
GameObject newEnemy = Instantiate(_enemyPrefab, posToSpawn, Quaternion.identity);
newEnemy.transform.parent = _enemyContainer;
yield return new WaitForSeconds(3.0f);
public void OnPlayerDeath()
{
_stopSpawning = true;
}
}
}
}