VR模拟枪支打靶,消灭鬼怪,换弹以及上弦等等硬核枪支操作。 使用HTCVive设备,开启SteamVR进行游玩。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.6 KiB

3 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
//定义玩家状态类,实现玩家的各种实时的玩家属性显示操作
//控制玩家镜头特效
public class Player : MonoBehaviour {
//数值相关
//生命值
[Range(0,100)]
public int hp;
//护甲
[Range(0, 100)]
public int armor;
//剩余手雷数
[Range(0, 6)]
public int grenades;
//承重
public float weightMax;
[Range(0f, 30f)]
public float weight;
//剩余弹药数
[Range(0, 100)]
public int bulletNumPercentage;
//敌方距离
[Range(0f, 60f)]
public float enemyDistance;
//剩余时间
[Range(0,59)]
public int remainSecond;
[Range(0, 59)]
public int remainMinute;
//玩家金钱
[Range(0,99999)]
public int playerMoney;
//显示相关
//能量相关
public Image hpImg;
public Text hpTxt;
public Image armorImg;
public Text armorTxt;
public Image grenadesImg;
public Text weightTxt;
public Image bulletNumPercentageImg;
public Text bulletNumPercentageTxt;
//上方信息相关
public Image enemyDistanceImg;
public Text enemyDistanceTxt;
public Text remainTimeTxt;
public Text playerMoneyTxt;
public Animator hurtAnime;
//玩家音效
public AudioSource hurtVoice;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (enemyDistance<=0) {
enemyDistance = 60f;
}
UpdateStatusUI();
if (!hurtAnime.GetBool("Pain") && hp <= 80)
{
hurtAnime.SetBool("Pain", true);
}
else if(hurtAnime.GetBool("Pain") && hp > 80) {
hurtAnime.SetBool("Pain",false);
}
}
//将数值转换为UI显示
private void UpdateStatusUI() {
hpImg.transform.localPosition = new Vector3(0f, -340f * (100 - hp) / 100f, 0f);
hpTxt.text = hp + "%";
armorImg.transform.localPosition = new Vector3(0f, -240f * (100 - armor) / 100f - 5f, 0f);
armorTxt.text = armor + "%";
grenadesImg.transform.localPosition = new Vector3(0f, -11f + (6 - grenades) * -19f, 0f);
weightTxt.text = weight + "/" + weightMax;
bulletNumPercentageImg.transform.localPosition = new Vector3(0f, -340f * (100 - bulletNumPercentage) / 100f, 0f);
bulletNumPercentageTxt.text = bulletNumPercentage + "%";
enemyDistanceImg.transform.localPosition = new Vector3(30f-enemyDistance,0f,0f);
enemyDistanceTxt.text = enemyDistance + " M";
remainTimeTxt.text = remainMinute / 10 + "" + (remainMinute - remainMinute / 10 * 10) + ":" + remainSecond / 10 + "" + (remainSecond - remainSecond / 10 * 10);
playerMoneyTxt.text = playerMoney+"";
}
public void Hurted(int damage) {
damage = damage * (100 - armor) / 100;
hp -= damage;
//下面是红眼动画
hurtAnime.SetTrigger("Attacked");
hurtVoice.Play();
}
//返回主菜单
public void returnMainMenu()
{
SceneManager.LoadScene(0);
}
//减速画面的制作(敌方死亡时几率触发)
private bool inSpeedUpStatus = false;
public void speedUp() {
if (!inSpeedUpStatus) {
inSpeedUpStatus = true;
StartCoroutine(speedUpAction());
}
}
IEnumerator speedUpAction() {
Time.timeScale = 0.25f;
yield return new WaitForSeconds(0.25f);
Time.timeScale = 1.0f;
inSpeedUpStatus = false;
}
}