How do I change the variable in another class?
public class Manager : MonoBehaviour {
public bool isDead = false;
void Start () {
GameObject Slugbert = (GameObject)Instantiate(Resources.Load("Slugbert"));
}
void Update () {
}
}
I'm trying to change the isDead boolean from false to true.
using UnityEngine;
using System.Collections;
using System;
public class Health : MonoBehaviour {
public GameObject obj;
Manager manager;
public int maxHealth = 10;
public int health = 10;
public GameObject deathInstance = null;
public Vector2 deathInstanceOffset = new Vector2(0,0);
void Start () {
manager = obj.GetComponent<Manager>();
health = maxHealth;
}
void Update () {
if (Input.GetKey ("up")) {
Debug.Log ("Self Destruct Activated");
TakeDamage();
}
}
public void TakeDamage()
{
health -= 100;
if (health <= 0)
{
OnKill();
Debug.Log ("Running it");
}
}
public void OnKill()
{
manager.isDead = true;
Debug.Log(manager.isDead);
if (deathInstance) {
var pos = gameObject.transform.position;
GameObject deathObject = Instantiate (deathInstance, new Vector3(pos.x + deathInstanceOffset.x, pos.y + deathInstanceOffset.y, pos.z), Quaternion.identity) as GameObject;
}
Destroy(gameObject);
}
}
I've added in a debug.log showing the value of manager.isDead, and it's printing true, however in the inspector when I run it and click on GameControl, the object containing Manager.cs it shows that isDead = false. I'm not sure how I get the value of isDead in GameControl Manager.cs to equal true.
Thanks, I'm pretty new to Unity