using System.Collections; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class Score_Script : MonoBehaviour { public string nextScene; private GameObject timeDisplay; private GameObject scoreDisplay; private GameObject bauteilDisplay; private void Start() { Cursor.visible = false; Static_GlobalStats.time = 0; Static_GlobalStats.levelScore = 0; Static_GlobalStats.bauteileLevel = 0; timeDisplay = GameObject.FindGameObjectWithTag("TimeDisplay"); scoreDisplay = GameObject.FindGameObjectWithTag("ScoreDisplay"); bauteilDisplay = GameObject.FindGameObjectWithTag("BauteilDisplay"); } void Update() { if (Static_GlobalStats.health > 0) Static_GlobalStats.time += Time.deltaTime; if (timeDisplay) timeDisplay.gameObject.GetComponent().text = "" + (int)Static_GlobalStats.time; if (scoreDisplay) scoreDisplay.gameObject.GetComponent().text = "" + (int)(Static_GlobalStats.totalScore + Static_GlobalStats.levelScore); if (bauteilDisplay) bauteilDisplay.gameObject.GetComponent().text = "" + (int)(Static_GlobalStats.bauteile + Static_GlobalStats.bauteileLevel) + "/" + (int)Static_GlobalStats.bauteileMax; if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } } private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Collectable") { Collectable_Script collectable = collision.gameObject.GetComponent(); Static_GlobalStats.levelScore += collectable.scoreValue; Static_GlobalStats.health = Mathf.Clamp(Static_GlobalStats.health + collectable.healthValue, 0, 100); Static_GlobalStats.lifes = Mathf.Clamp(Static_GlobalStats.lifes + collectable.lifeValue, 0, 99); if (collision.gameObject.GetComponent()) collision.gameObject.GetComponent().Play(); collision.gameObject.GetComponent().enabled = false; Rigidbody2D coinRB = collision.gameObject.GetComponent(); coinRB.AddForce(Vector2.up * 1000); } else if (collision.gameObject.tag == "Finish") { gameObject.GetComponent().bodyType = RigidbodyType2D.Kinematic; Static_GlobalStats.totalScore += Static_GlobalStats.levelScore; Static_GlobalStats.levelScore = 0; Static_GlobalStats.bauteile += Static_GlobalStats.bauteileLevel; Static_GlobalStats.bauteileLevel = 0; if (nextScene != null && nextScene != "") SceneManager.LoadScene(nextScene); else SceneManager.LoadScene("Menu_Main"); } } }