Ich entwickle ein crystal match 3
Spiel mit Unity3d.Gesundheit Schieberegler nicht arbeiten
Ich fügte die Health
Funktion hinzu. Es funktioniert nicht richtig. Jedes Mal, wenn ich die energie
ändere, geht es auf 0. Ich habe versucht, es um -10
vom Anfangswert 100
zu reduzieren.
Können Sie mir helfen?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class score : MonoBehaviour
{
public Slider energieSlider;
public static int points = 0;
public static int level = 1;
public static int stars = 0;
public static int die = 0;
public static int tap = 0;
public static int start = 0;
public static int Score = 0;
public static int share = 0;
public static int login = 0;
public static int energie = 100;
public Text scoreText;
public Text levelText;
public Text starsText;
public static int totalpoints = 0;
public void addhealth()
{
energieSlider.value += 100;
}
public void removehealth()
{
energieSlider.value -= 10;
energie -= 10;
points = 0;
}
// Use this for initialization
//public void onClickScoreButton()
//{
//points++;
//}
// Update is called once per frame
void Update()
{
scoreText.text = "Score: " + points;
levelText.text = "Level: " + level;
starsText.text = "Stars: " + stars;
totalpoints += points;
PlayerPrefs.SetInt("totalpoints", + totalpoints);
PlayerPrefs.SetInt("score", totalpoints);
if (points >= 1000)
{
totalpoints += points;
PlayerPrefs.SetInt("totalpoints", + totalpoints);
PlayerPrefs.SetInt("score", totalpoints);
stars += 1;
Invoke("removehealth", 0f);
points = 0;
//energieSlider.value = energie;
}
if (stars == 3)
{
level += 1;
//call archiment scene
//points = 0;
totalpoints = points;
PlayerPrefs.SetInt("totalpoints", totalpoints);
PlayerPrefs.SetInt("score", points);
Application.LoadLevel("Cristals Scores");
}
//if (totalpoints == 1001)
//{
//energie -= 10;
//PlayerPrefs.SetInt("tap", tap);
//}
if (energieSlider.value <= 0)
{
die += 1;
PlayerPrefs.SetInt("die", die);
//wait 3 secs
System.Threading.Thread.Sleep(3000);
//game over scene
Application.LoadLevel("gameover");
}
}
void Start()
{
energieSlider.value = 1000;
//if (energieSlider != null)
//{
//energieSlider.IsActive();
//}
totalpoints = PlayerPrefs.GetInt("totalpoints");
tap = PlayerPrefs.GetInt("tap");
die = PlayerPrefs.GetInt("die");
start = PlayerPrefs.GetInt("start");
stars = PlayerPrefs.GetInt("stars");
//totalpoints = PlayerPrefs.GetInt("score");
energie = PlayerPrefs.GetInt("energie");
}
}