78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class Bullet_movement_Enemy : MonoBehaviour
|
|
{
|
|
[SerializeField] float dmg = 0.0f;
|
|
[SerializeField] private float verticalSpeed = 15.0f;
|
|
public float remainInAir = 1.0f;
|
|
private float counter = 0f;
|
|
private Slider slider;
|
|
private GameObject uiElement;
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
slider = FindObjectOfType<Slider>(); //Findet den ersten slider in der scene - hier den Healthbar
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Movement();
|
|
}
|
|
|
|
private void Movement()
|
|
{
|
|
transform.Translate(Vector3.up * Time.deltaTime * verticalSpeed); // bullet geschwindigkeit
|
|
counter += Time.deltaTime;
|
|
|
|
if (counter >= remainInAir)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Starship"))
|
|
{
|
|
Destroy(gameObject); // berechnet den dmg
|
|
slider.value -= dmg;
|
|
}
|
|
|
|
if (other.CompareTag("Starship") && slider.value <= 0f) // zerstört das Starship bei 0hp oder weniger
|
|
{
|
|
other.gameObject.GetComponent<OnPlayerDeath>().onDeathUI();
|
|
Destroy(other.gameObject);
|
|
|
|
if(other.gameObject.CompareTag("Dead"))
|
|
{
|
|
uiElement.SetActive(true);
|
|
}
|
|
if (other.gameObject.CompareTag("Score"))
|
|
{
|
|
uiElement.SetActive(false);
|
|
}
|
|
if (other.gameObject.CompareTag("Highscore"))
|
|
{
|
|
uiElement.SetActive(false);
|
|
}
|
|
if (other.gameObject.CompareTag("RoundCounter"))
|
|
{
|
|
uiElement.SetActive(false);
|
|
}
|
|
if (other.gameObject.CompareTag("EnemiesLeft"))
|
|
{
|
|
uiElement.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|