PlaneRun/Assets/Scripts/PLayerLife.cs

106 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PLayerLife : MonoBehaviour
{
public float Hp = 3;
public bool shieldEnabled;
public GameObject Hp3;
public GameObject Hp2;
public GameObject Hp1;
public bool life;
public GameObject effect1;
public GameObject effect2;
public GameObject gameOver;
public GameObject Cam;
public Animator animCam;
public bool Shake = false;
public PickupManager pickupManager;
// Start is called before the first frame update
void Start()
{
Shake = false;
animCam = Cam.GetComponent<Animator>();
effect1.SetActive(false);
effect2.SetActive(false);
life = true;
}
// Update is called once per frame
void Update()
{
if(Hp == 3)
{
effect1.SetActive(false);
effect2.SetActive(false);
Hp3.SetActive(true);
Hp2.SetActive(false);
Hp1.SetActive(false);
}
if (Hp == 2)
{
effect1.SetActive(true);
effect2.SetActive(false);
Hp3.SetActive(false);
Hp2.SetActive(true);
Hp1.SetActive(false);
}
if (Hp == 1)
{
effect1.SetActive(true);
effect2.SetActive(true);
Hp3.SetActive(false);
Hp2.SetActive(false);
Hp1.SetActive(true);
}
if(Hp <= 0)
{
life = false;
gameOver.SetActive(true);
pickupManager.ClearPickups();
}
if (Shake)
{
Handheld.Vibrate();
Shake = false;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("missle"))
{
Shake = true;
if (!shieldEnabled)
{
Hp -= 1;
}
else
{
pickupManager.shieldPickup.DisableShield();
}
}
if (other.CompareTag("parachute"))
{
if(Hp < 3)
{
Hp += 1;
if (shieldEnabled)
{
pickupManager.shieldPickup.UpdateUI();
}
}
}
}
}