123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour {
- public static PlayerController Instance;
- public float MoveSpeed;
- private GameObject bullet;
- private float timecount;
- public float FireCD;
- private Transform firePos;
- private float time;
- public GameObject explode;
- private void Awake()
- {
- Instance = this;
- }
- // Use this for initialization
- void Start () {
- bullet = Resources.Load<GameObject>("Prefabs/Bullet");
- firePos = transform.Find("FirePos0");
- PlaneManager.instance.PlayerHP = 20;
- explode = Resources.Load<GameObject>("Prefabs/Explode");
- }
-
- // Update is called once per frame
- void Update () {
- Move();
- //Fire();
- NormalFire();
- // SuperFire();
- isDeath();
-
- }
- //键盘控制飞机移动 用mathf方法限制飞机移动的范围
- void Move()
- {
- if (Input.GetKey(KeyCode.A))
- {
- transform.Translate(Vector3.right * MoveSpeed * Time.deltaTime);
- }
- if (Input.GetKey(KeyCode.D))
- {
- transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
- }
- if (Input.GetKey(KeyCode.W))
- {
- transform.Translate(Vector3.up * MoveSpeed * Time.deltaTime);
- }
- if (Input.GetKey(KeyCode.S))
- {
- transform.Translate(Vector3.down * MoveSpeed * Time.deltaTime);
- }
- transform.position = new Vector3(Mathf.Clamp(transform.position.x, -6.37f, 6.64f), Mathf.Clamp(transform.position.y, -6.595f, 6.595f), Mathf.Clamp(transform.position.z, -6.9f, 6.5f));
- }
- private void NormalFire()
- {
-
- timecount += Time.deltaTime;
- if (timecount >= FireCD)
- {
- GameObject go = Instantiate(bullet);
- go.transform.position = LookAtFj.Instance.transform.position;
- go.transform.eulerAngles = new Vector3( LookAtFj.Instance.transform.eulerAngles.x-180f, LookAtFj.Instance.transform.eulerAngles.y, LookAtFj.Instance.transform.eulerAngles.z);
- timecount = 0;
- }
- }
-
- //private void SuperFire()
- //{
- // timecount += Time.deltaTime;
- // if (timecount >= FireCD)
- // {
- // for (int i = 0; i < 5; i++)
- // {
- // GameObject go = Instantiate(bullet);
- // go.transform.position = transform.Find("FirePos" + i).position;
- //
- // }
- //
- // timecount = 0;
- // }
- //}
- //受伤 减血
- public void BeHit()
- {
- PlaneManager.instance.PlayerHP-=5 ;
-
- }
- private void isDeath()
- {
- if (false)//PlaneManager.instance.PlayerHP <= 0
- {
- ScoreManager.instance.SetScore();
- UIManager.instance.CreatePanel("PanelOver");
- UIManager.instance.DestroyPanel("PanelGame");
- CreateStone.instance.stopStone();
- CreateStone.instance.stopProp();
- Destroy(this.gameObject);
- }
- }
- //碰撞检测 如果碰到的stone 触发受伤方法 生成爆炸特效
- private void OnTriggerEnter(Collider other)
- {
- if (other.tag=="stone")
- {
- BeHit();
- GameObject go = Instantiate(explode);
- go.transform.position = other.transform.position;
- Destroy(other.gameObject);
- }
- //如果碰到的是道具 血量加满
- if (other.tag=="prop")
- {
-
-
- PlaneManager.instance.PlayerHP = 20;
-
-
- //PlaneManager.instance.PlayerHP +=5;
- //PanelGame.instance.blood.transform.localScale = new Vector3(1, 1, 1);
- Destroy(other.gameObject);
- }
- }
-
- }
- //void Fire()
- //{
- // if (Input.GetKey(KeyCode.Q))
- // {
- // NormalFire();
- // }
- // if (Input.GetKey(KeyCode.E))
- // {
- // SuperFire();
- // }
- //}
|