using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class score : MonoBehaviour {
public Text scoretext;
public int ballvalue;
// Use this for initialization
public int scorevalue;
public gamecontroller GC;
public Text highscore;
void Start () {
scorevalue = 0;
highscore.text = PlayerPrefs.GetInt ("HIGH SCORE:
",0).ToString();
Updatescore ();
updatehighscore ();
}
void OnTriggerEnter2D()
{
scorevalue += ballvalue;
GC.timeleft = Time.deltaTime +20 ;
Updatescore ();
timer ();
}
void OnCollisionEnter2D(Collision2D collision){
if (collision.gameObject.tag == "Bomb") {
scorevalue -= ballvalue ;
Updatescore ();
}
}
// Update is called once per frame
void Updatescore () {
updatehighscore ();
scoretext.text = "score:
" + scorevalue;
}
void updatehighscore() {
if (scorevalue > PlayerPrefs.GetInt ("HIGH score:
", 0))
{
PlayerPrefs.SetInt ("HIGH SCORE:
", scorevalue);
highscore.text = scorevalue.ToString ();
}
}
void timer()
{
GC.timertext.text = "Time Left:
" + Mathf.RoundToInt (GC.timeleft);
}
}
,