x


Point counter = 0 if change level ... HOW ?

Hello. I have a very simple question. I have a game with 2 maps. On the 2 maps you can destroy objects with a gun ... but when I change the map I want to have again 0 Kills on the Point Counter. Now if I change the level the kills remain saved. How can I make that if I change level Point Count = 0 ?

Here are my scripts:

using UnityEngine;
using System.Collections;

public class PointCounter : MonoBehaviour {
    public GUISkin guiSkin = null;
    public static int points = 0;

    void OnGUI()
    {
        GUI.skin = guiSkin;
        GUI.Label(new Rect(317.0f, 78.5f, 400.0f, 120.0f), points.ToString());
        GUI.skin = null;
    }
    void Awake() {
        DontDestroyOnLoad(transform.gameObject);
    }
}

and the 2nd script is:

using UnityEngine; using System.Collections;

public class Zombie : MonoBehaviour {

public int points = 1; // You can edit this in the inspector

void OnDestroy()
{
    PointCounter.points += points;
}   void OnDontDestroy()
{
    PointCounter.points -= points;
}   void Awake() {
    DontDestroyOnLoad(transform.gameObject);
} }

I NEED VERY FAST HELP! Thank you in advance for every answer :)

more ▼

asked Oct 08 '11 at 08:17 PM

worldofcars gravatar image

worldofcars
125 16 24 30

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

if(Application.Loadlevel(1)) { Points = 0; }

that may work

more ▼

answered Mar 17 '12 at 05:40 PM

09jgriffin gravatar image

09jgriffin
23 4 12 15

(comments are locked)
10|3000 characters needed characters left

It's in the nature of static vars that it won't reset, but I'll save that speech for another time. The easiest way is just to reset it as soon as the object loads.

using UnityEngine; using System.Collections;

public class PointCounter : MonoBehaviour { public GUISkin guiSkin = null; public static int points = 0;

void OnGUI()
{
    GUI.skin = guiSkin;
    GUI.Label(new Rect(317.0f, 78.5f, 400.0f, 120.0f), points.ToString());
    GUI.skin = null;
}
void Awake() {
    DontDestroyOnLoad(transform.gameObject);
    //--New Stuff---
    points = 0;
    //-------------
}

}

more ▼

answered Oct 08 '11 at 08:22 PM

Peter G gravatar image

Peter G
15k 16 44 136

Thank you for the fast answer. I will try it out tomorrow (in 14 hours) and I hope this will work.

other answers are welcome :)

Oct 08 '11 at 08:48 PM worldofcars
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x379
x322
x132
x100
x5

asked: Oct 08 '11 at 08:17 PM

Seen: 759 times

Last Updated: Mar 17 '12 at 05:40 PM