private static bool ball = false;
public static int score;
private int Highscore;
private bool isGrounded = false;
private static int lifeinhand;
private bool postion;
void Awake()
{
Highscore = PlayerPrefs.GetInt("TheNewHighscore");
}
// Use this for initialization
void Start () {
postion = false;
lifeinhand = 3;
ball = false;
score = 0;
}
// Update is called once per frame
void Update () {
// if(score < 1000)
// {
// Vector3 movement = (Input.GetAxis("Horizontal") * -Vector3.left * 5.0f);
// rigidbody.AddForce(movement, ForceMode.Force);
// }
if(score < 1000)
gameObject.transform.Translate(Input.GetAxis("Horizontal") * 0.04f,0.0f, 0.0f, Space.World);//rigidbody.mass = 10.0f;
if(score > 1000 score < 2000)
gameObject.transform.Translate(Input.GetAxis("Horizontal") * 0.07f,0.0f, 0.0f, Space.World);//rigidbody.mass = 10.0f;
if(score > 2000)
gameObject.transform.Translate(Input.GetAxis("Horizontal") * 0.1f,0.0f, 0.0f, Space.World);//rigidbody.mass = 10.0f;
if(gameObject.transform.position.y < -5.0f || gameObject.transform.position.y > 7.0f)
{
postion = true;
}
if(ball)
{
if(score > Highscore)
{
PlayerPrefs.SetInt("TheNewHighscore:", score);
}
}
}
void FixedUpdate()
{
//calculating the score when moving from one platform to another
if(!ball)
{
isGrounded = Physics.Raycast(transform.position, -Vector3.up, 1.0f);
if (isGrounded)
{
score +=0;
}
else
score +=1;
}
//keep the ball to the corresponding position
if(postion lifeinhand > 0)
{
gameObject.transform.position = new Vector3(Random.Range(-1,2), Random.Range(0,1), 0.0f);
lifeinhand = lifeinhand-1;
postion = false;
}
//gameover when lose all the life line
if(lifeinhand <=0)
{
ball = true;
postion = false;
lifeinhand = 0;
}
}
void OnGUI()
{
GUI.color = Color.white;
GUI.Label(new Rect(0.0f, 100.0f, 1000.0f, 100.0f), "Your Score:"+ score);
GUI.Label(new Rect(0.0f, 150.0f, 1000.0f, 100.0f), "HighScore:"+ Highscore);
GUI.Label(new Rect(0.0f, 50.0f, 1000.0f, 100.0f), "Life In Hand:"+lifeinhand);
// if(gameObject.transform.position.y < -8.0f gameObject.transform.position.y < 1000)
// {
// lifeinhand = 2;
// if(ball)
// Instantiate(gameObject, new Vector3(Random.Range(-10.11f,7.75f), Random.Range(0, 2), 0.0f), Quaternion.identity);
// }
if(ball)
{
GUI.Label(new Rect(300, 250, 500, 500), "GAME OVER");
if(GUI.Button(new Rect(300, 350, 200, 100), "Restart"))
{
Application.LoadLevel("test1");
}
}
}
this is my script the playerprefs doesnt works i dont know why.
if you have any idea please tell me?
Siva.