Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine.UI;
- using UnityEngine;
- public class Spieler : MonoBehaviour
- {
- public GameObject Gewinn;
- float eingabeFaktor = 10;
- void Update()
- {
- //Eingabe Speichern
- float xEingabe = Input.GetAxis("Horizontal");
- float yEingabe = Input.GetAxis("Vertical");
- if (yEingabe < 0)
- {
- return;
- }
- //Neue Position Bestimmen
- float xNeu = transform.position.x +
- xEingabe * eingabeFaktor * Time.deltaTime;
- if (xNeu > 8.3f)
- {
- xNeu = 8.3f;
- }
- if (xNeu < -8.3f)
- {
- xNeu = -8.3f;
- }
- float yNeu = transform.position.y +
- (yEingabe * eingabeFaktor * Time.deltaTime);
- transform.position = new Vector3(xNeu, yNeu, 0);
- }
- void NaechstesLeben()
- {
- transform.position = new Vector3(0, -4.4f, 0);
- gameObject.SetActive(true);
- }
- int anzahlPunkte = 0;
- public Text punkteAnzeige;
- private int anzahlPunkte;
- void OnCollisionEnter2D(Collision2D collision)
- {
- if (collision.gameObject.tag == "Gewinn")
- {
- anzahlPunkte = anzahlPunkte + 1;
- if (anzahlPunkte < 6)
- punkteAnzeige.text = "Punkte" + anzahlPunkte;
- else
- {
- gameObject.SetActive(false);
- Gewinn.SetActive(false);
- punkteAnzeige.text = "Gewonnen";
- }
- float xNeu = Random.Range(-8.0f, 8.0f);
- float yNeu;
- if (anzahlPunkte < 2) yNeu = -2.7f;
- else if (anzahlPunkte < 4) yNeu = 0.15f;
- else yNeu = 3;
- Gewinn.transform.position = new Vector3(xNeu, yNeu, 0);
- }
- else if (collision.gameObject.tag == "Enemy")
- {
- gameObject.SetActive(false);
- Invoke("NaechstesLeben", 2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement