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.

62 lines
1.6 KiB

3 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
//靶子类
//该靶子在平常情况下会在轨道上面移动
//当靶子被打倒时停止
public class Target_1 : Hurtable {
[Range(0.0f,10f)]
public float speed;
//运动的起始与结束位置
private float nowX;
public float startX;
public float endX;
//运动方向
private bool isLeft;
private bool isActive;
// Use this for initialization
void Start () {
deathEvent.AddListener(StopMode);
nowX = myself_1.transform.localPosition.x;
isLeft = false;
isActive = true;
}
// Update is called once per frame
void Update () {
if (isActive) {
ActiveMode();
}
}
//靶子在轨道上面运动的模式
public void ActiveMode() {
if (nowX < endX && isLeft) {
myself_1.transform.localPosition += new Vector3(Time.deltaTime * speed, 0, 0);
nowX += Time.deltaTime * speed;
} else if (nowX > startX && !isLeft) {
myself_1.transform.localPosition -= new Vector3(Time.deltaTime * speed, 0, 0);
nowX -= Time.deltaTime * speed;
}
if (nowX >= endX && isLeft)
{
isLeft = false;
}
else if(nowX <=startX && !isLeft) {
isLeft = true;
}
}
//靶子在轨道上面停止的模式
public void StopMode() {
isActive = false;
gameObject.AddComponent<Rigidbody>();
gameObject.GetComponent<NavMeshObstacle>().enabled = false;
gameObject.transform.localEulerAngles += new Vector3(5f,0f,0f);
}
}