hello to all!
I’m making a memory card game. i flip two card objects in my game and when i click on them both (which they have the same image) i get 10points and they both get destroyed. I have a js script ScoreManager that controls the points. Also there is a timer counts and if it becomes equal to zero then a game over GUITexture appears and loads back the main menu.
This is the js script for card 1 (there is another one js script for gameobject card 2):
function OnMouseDown () {
card_1.transform.localRotation.z = 180;
flipedCard = true;
Invoke("CheckCards", 1);
}
function CheckCards(){
if((flipedCard == true) && (Flip_card_2.flipedCard == true)){
flag=true;
Destroy(card_1);
}
else if(flipedCard == true){
card_1.transform.localRotation.z =0;
flipedCard=false;
}
}
//variables
public var card_1: GameObject;
card_1 = GameObject.Find("card_1");
public static var flag:boolean=false;
public static var flipedCard:boolean=false;
ScoreManager js code below, attached to my points GUIText object:
public var p:int;
public var p1:int;
public var pointsClip: AudioClip;
public var flag_:boolean;
function Start(){
p = 0;
p1=0;
guiText.text = "0";
flag_ = false;
}
function Update () {
if(Flip_card_1.flag == true || Flip_card_2.flag==true){
p1 = 10;
if(flag_ == false){
audio.PlayOneShot(pointsClip);
flag_ = true;
}
}
p = p1;
guiText.text = ""+ p;
}
The problem is after the game over GUITexture (it brings me back to main menu and) reloads my scene again and the points GUIText shows the last points i got from my last score (ex. points=10) instead of showing my points back to 0 (as i set on Start() ). Why is that happening?