I was coding normally but then in the console this error appeared: Assets\Scripts\Target.cs(38,24): error CS1061: ‘GameManager’ does not contain a definition for ‘isGameActive’ and no accessible extension method ‘isGameActive’ accepting a first argument of type ‘GameManager’ could be found (are you missing a using directive or an assembly reference?)
and my Game Manager has a definition of isGameActive
Script 1:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Target : MonoBehaviour
{
private Rigidbody targetRb;
private float minSpeed = 12;
private GameManager gameManager;
private float maxSpeed = 16;
private float maxTorque = 10;
private float xRange = 4;
private float ySpawnPos = -6;
public int pointValue;
public ParticleSystem explosionParticles;
// Start is called before the first frame update
void Start()
{
targetRb = GetComponent();
targetRb.AddForce(RandomForce(), ForceMode.Impulse);
targetRb.AddTorque(RandomTorque(), RandomTorque(), RandomTorque(), ForceMode.Impulse);
transform.position = RandomSpawnPos();
gameManager = GameObject.Find(“Game Manager”).GetComponent();
}
// Update is called once per frame
void Update()
{
}
private void OnMouseDown()
{
if(gameManager.isGameActive)
{
Destroy(gameObject);
gameManager.UpdateScore(pointValue);
Instantiate(explosionParticles, transform.position, explosionParticles.transform.rotation);
}
}
private void OnTriggerEnter(Collider other)
{
Destroy(gameObject);
if (!gameObject.CompareTag(“Bad”))
{
gameManager.GameOver();
}
}
Vector3 RandomForce()
{
return Vector3.up * Random.Range(minSpeed, maxSpeed);
}
float RandomTorque()
{
return Random.Range(-maxTorque, maxTorque);
}
Vector3 RandomSpawnPos()
{
return new Vector3(Random.Range(-xRange, xRange), ySpawnPos);
}
}
Script 2:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class GameManager : MonoBehaviour
{
public List targets;
private float spawnRate = 1.0f;
private int score;
public TextMeshProUGUI scoreText;
public bool isGameActive;
public TextMeshProUGUI gameOverText;
// Start is called before the first frame update
void Start()
{
StartCoroutine(SpawnTarget());
score = 0;
UpdateScore(0);
isGameActive = true;
}
// Update is called once per frame
void Update()
{
}
IEnumerator SpawnTarget()
{
while(isGameActive)
{
yield return new WaitForSeconds(spawnRate);
int index = Random.Range(0, targets.Count);
Instantiate(targets[index]);
}
}
public void UpdateScore(int scoreToAdd)
{
score += scoreToAdd;
scoreText.text = "SCORE: " + score;
}
public void GameOver()
{
gameOverText.gameObject.SetActive(true);
isGameActive = false;
}
}