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.
 
 
 
 
 

82 lines
2.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using HTC.UnityPlugin.Vive;
//治疗针的使用
//针在平常状态下会缓慢恢复数值,针在治疗状态下按住扳机使玩家缓慢恢复生命值
//如果不使用,20秒之后针的恢复量会补充完毕
//使用状态(按下状态)最多持续1秒,恢复30点生命值
public class CureNeedle : MonoBehaviour {
//是否在治疗状态
private bool isCure_;
//是否碰到左手
private bool isTouchLeftHand_;
//获取玩家类脚本
private Player playerScript;
private PlayerControl playerControlScript;
//数值显示
public Image remainHpImg;
public GameObject Light;
private bool isRayCast;
private RaycastHit NeedleRay;
// Use this for initialization
void Start () {
isTouchLeftHand_ = false;
isCure_ = false;
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
playerControlScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerControl>();
}
// Update is called once per frame
void Update() {
if (isTouchLeftHand_) {
if (ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger))
{
isCure_ = true;
}
}
if (ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Trigger)) {
isCure_ = false;
Light.SetActive(false);
}
if (isCure_ && playerControlScript.needleHpRemain > 0 && playerScript.hp < 100) {
playerControlScript.needleHpRemain = playerControlScript.needleHpRemain - 1;
playerScript.hp += 1;
}
remainHpImg.fillAmount = playerControlScript.needleHpRemain / 30f;
Debug.DrawRay(gameObject.transform.position - gameObject.transform.up * -0.025f -gameObject.transform.forward * 0.125f, gameObject.transform.forward * 0.2f, Color.red);
isRayCast = Physics.Raycast(gameObject.transform.position - gameObject.transform.up * -0.025f - gameObject.transform.forward * 0.125f, gameObject.transform.forward, out NeedleRay, 0.2f);
if (isRayCast)
{
if (NeedleRay.transform.tag == "leftHandCollider" && !isTouchLeftHand_)
{
isTouchLeftHand_ = true;
Light.SetActive(true);
}
}
else if(isTouchLeftHand_) {
isTouchLeftHand_ = false;
Light.SetActive(false);
}
}
private void OnTriggerEnter(Collider other)
{
print(other.name);
if (other.name == "SphereCollider")
{
isTouchLeftHand_ = true;
Light.SetActive(true);
}
}
}