|
@@ -1,19 +1,48 @@
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
+using UnityEngine.UI;
|
|
|
|
|
|
public class PlayerControl : MonoBehaviour
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// 最小速度
|
|
|
+ /// </summary>
|
|
|
public float minSpeed = 0.7f;
|
|
|
+ /// <summary>
|
|
|
+ /// 最大速度
|
|
|
+ /// </summary>
|
|
|
public float maxSpeed = 1.4f;
|
|
|
+ /// <summary>
|
|
|
+ /// 爆炸特效
|
|
|
+ /// </summary>
|
|
|
+ public GameObject explose;
|
|
|
|
|
|
+ public float currentValue;
|
|
|
+ public float maxValue = 100;
|
|
|
+
|
|
|
+ public Slider armorSlider;
|
|
|
+ public Text currentText;
|
|
|
+ public Text maxText;
|
|
|
+
|
|
|
+ private CameraFollow cf;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 鼠标到飞船的距离
|
|
|
+ /// </summary>
|
|
|
private float dis = 0;
|
|
|
+ /// <summary>
|
|
|
+ /// 飞船的速度
|
|
|
+ /// </summary>
|
|
|
private float player_speed = 0;
|
|
|
|
|
|
// Use this for initialization
|
|
|
void Start()
|
|
|
{
|
|
|
-
|
|
|
+ currentValue = maxValue;
|
|
|
+ UpdateContent();
|
|
|
+
|
|
|
+ cf = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollow>();
|
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
@@ -48,10 +77,36 @@ public class PlayerControl : MonoBehaviour
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other)
|
|
|
{
|
|
|
- Destroy(other.gameObject);
|
|
|
+ if (other.tag == "enemy")
|
|
|
+ {
|
|
|
+
|
|
|
+ Instantiate(explose, other.gameObject.transform.position, Quaternion.identity);
|
|
|
+ cf.Shake();
|
|
|
+ GetHurt(50);
|
|
|
+ Destroy(other.gameObject);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ void GetHurt(int damage)
|
|
|
+ {
|
|
|
+ if (currentValue > 0)
|
|
|
+ {
|
|
|
+ currentValue -= damage;
|
|
|
+ UpdateContent();
|
|
|
+ if (currentValue <= 0)
|
|
|
+ {
|
|
|
+ Instantiate(explose, transform.position, Quaternion.identity);
|
|
|
+ GameManage.Instance.GameOver();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ void UpdateContent()
|
|
|
+ {
|
|
|
+ currentText.text = currentValue.ToString();
|
|
|
+ maxText.text = "/" + maxValue.ToString();
|
|
|
+ armorSlider.value = (currentValue / maxValue);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|