so… i have this game where you get 1 point for killing an enemy
if the enemy touches you
it loads another scene (scene 2)
but if i kill the enemy i score the point then another enemy kills me
it loads the scene 2 and the score reads 7…
if my score is 2, on the secound scene will be 12
why this happens?
i want just to keep my score as it was in scene 1
here is my code
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public static int count = 0;
// Use this for initialization
void Start () {
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update () {
if (count == 200) {
print ("lol");
Instantiate(Resources.Load ("Cube (1)")); count ++;
}
if (count == 300) {
print ("lol");
Instantiate(Resources.Load ("Cube (1)")); count ++;
}
}
void OnGUI () {
GUI.Label (new Rect (48, 10, 100, 30),"Kills = " + count);
}
}
and another script in case you need it
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Player_Health : MonoBehaviour {
public AudioClip heart;
public int health = 20;
public int TheDammage = 5;
public int TheCure = 50;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void Awake ()
{
DontDestroyOnLoad (this.gameObject);
}
void OnGUI () {
GUI.Label (new Rect (50, 25, 100, 30),"health = " + health);
}
void OnCollisionEnter (Collision collision) {
if (collision.gameObject.tag == "Healer") {
health += TheCure;
}
if (collision.gameObject.tag == "Enemy") {
health -= TheDammage;
}
if (health <= 0) {
KillPlayer ();
}
if (health <= 150) {
GetComponent<AudioSource>().Play ();
}
if (health >= 200) {
GetComponent<AudioSource>().Stop ();
}
}
public void KillPlayer(){
SceneManager.LoadScene ("2" );
health += 200;
//Destroy (gameObject);
//transform.gameObject.tag = "Finish";
}
}
and… im not done yet xD
for the score to work i have this on my enemy
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int scoreValue = 1;
public int enemyHealth = 20;
public int TheDammage = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter (Collision collision) {
if (collision.gameObject.tag == "bullet") {
enemyHealth -= TheDammage;
}
if (enemyHealth <= 0) {
Destroy (gameObject);
}
}
void OnDestroy(){
Score.count += scoreValue;
}
}
i’ve readed these scripts over and over again and i can’t figure nothing
what’s wrong? im verry bad at scripting but this is soo weird that i can’t figure it out by my own