1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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>().text = "" + (int)Static_GlobalStats.time;
- if (scoreDisplay) scoreDisplay.gameObject.GetComponent<Text>().text = "" + (int)(Static_GlobalStats.totalScore + Static_GlobalStats.levelScore);
- if (bauteilDisplay) bauteilDisplay.gameObject.GetComponent<Text>().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<Collectable_Script>();
- 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<AudioSource>()) collision.gameObject.GetComponent<AudioSource>().Play();
- collision.gameObject.GetComponent<Collider2D>().enabled = false;
- Rigidbody2D coinRB = collision.gameObject.GetComponent<Rigidbody2D>();
- coinRB.AddForce(Vector2.up * 1000);
- }
- else if (collision.gameObject.tag == "Finish")
- {
- gameObject.GetComponent<Rigidbody2D>().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");
- }
- }
- }
|