I have 2 different scripts. 1 of them has int variable count and the other one goes and changes it’s value. But I get this error. Can you check it?
First Script:
using UnityEngine;
using System.Collections;
public class Spawn : MonoBehaviour
{
public GameObject monsterPrefab; // Set this in inspector to the monster prefab.
public float Delay;
public int count;
public float canSpawn;
void Update()
{
if (Time.time >= canSpawn)
{
if (count < 3)
{
Instantiate(monsterPrefab, transform.position, transform.rotation);
count++;
canSpawn += Delay + Time.time;
}
}
}
}
Second Script:
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour
{
public float health;
Spawn script;
private bool _damagedealth = false;
private GameObject target;
void Start()
{
health = 100;
target = GameObject.FindGameObjectWithTag("Player");
script = GetComponent<Spawn>();
}
void Update ()
{
if (health <= 0)
{
Destroy(this.gameObject);
script.count -= 1;
}
}