- Home /
Question by
nibek1000 · Sep 23, 2016 at 11:41 AM ·
scripting problemiflives
Editing score betwen scripts?
Hi I have 2 script:
using UnityEngine;
using System.Collections;
public class _GameManager : MonoBehaviour {
static int lifes= 3;
public GUISkin guiSkin;
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
void OnGUI (){
GUI.skin = guiSkin;
GUI.Label( new Rect((Screen.width / 2) - 60,10, 200, 30), "Lifes: " + lifes);
}
}
and:
using UnityEngine;
using System.Collections;
public class ZlaOdpowiedz : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
_GameManager.lifes -= 1;
Destroy(other.gameObject);
Application.LoadLevel(1);
}
}
I think you see what Im trying to do... I get error and I cant repair it, someone can help me?
wanna to make "if (lifes == 0){ Application.LoadLevel (1); } or somethink like thet
Thanks anyway ;)
Comment
Answer by Andrey-Postelzhuk · Sep 23, 2016 at 12:19 PM
Your variable is private. You wrote:
static int lifes;
By default it'll be private. I think you need this:
public static int lifes;
Your answer
![](https://koobas.hobune.stream/wayback/20220612093305im_/https://answers.unity.com/themes/thub/images/avi.jpg)