using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class Rigth_hand : MonoBehaviour {
public static Rigth_hand instance;
SteamVR_TrackedObject trackobject;
SteamVR_Controller.Device device;
private bool stopzhendong;
public GameObject feibiao;
private Quaternion rotation;
private GameObject obj;
public GameObject cube;
private int number;
public GameObject uichengji;
public Text textTotalScores;
public Text onenumber;
public int one;
public Text twonumber;
public int two;
public Text threenumber;
public int three;
public Text fournumber;
public int four;
public Text zuigaofen;
private int lishizuigao;
private int scores=0;
private int numberscores;
private bool stop;
// private bool fei;
// Use this for initialization
void Start () {
instance = this;
if (PlayerPrefs.GetInt("Scores")==0)
{
PlayerPrefs.SetInt("Scores", scores);
}
trackobject = transform.GetComponent<SteamVR_TrackedObject>();
rotation = new Quaternion();
rotation.eulerAngles = new Vector3(90,0,0);
}
// Update is called once per frame
void Update () {
Shexian();
if (obj != null)
{
obj.transform.LookAt(cube.transform);
}
}
void Shexian()
{
try
{
device = SteamVR_Controller.Input((int)trackobject.index);
}
catch (System.Exception)
{
throw;
}
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
{
number++;
if (number <= 20)
{
//fei = false;
obj = GameObject.Instantiate(feibiao, transform.position+new Vector3(0,0.05f,0), transform.rotation);
obj.transform.SetParent(transform);
stop = true;
SnyScores();
}
else
{
if (stop == true)
{
print("stop");
if (scores> PlayerPrefs.GetInt("Scores", 0))
{
PlayerPrefs.SetInt("Scores", scores);
print("进来了");
}
lishizuigao = PlayerPrefs.GetInt("Scores", 0);
zuigaofen.text = "Highest:" + lishizuigao;
stop = false;
uichengji.SetActive(true);
}
}
stopzhendong = true;
}
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
{
stopzhendong = false;
if (obj != null)
{
if(number <= 20)
{
//fei = true;
obj.GetComponent<Rigidbody>().isKinematic = false;
obj.transform.SetParent(null);
tossObject(obj.GetComponent<Rigidbody>());
}
}
}
if (stopzhendong==true)
{
device.TriggerHapticPulse(500);
}
//if (fei == true)
//{
// obj.transform.GetComponent<Rigidbody>().AddRelativeForce(Vector3.down * 500);
// print("111");
//}
}
void tossObject(Rigidbody rigidbody)
{
//如果是起始位置,则设置为起始位置,否则设置为父类
Transform origin = trackobject.origin ? trackobject.origin : trackobject.transform.parent;
//如果起始位置部位空
if (origin != null)
{
//将局部坐标转换成世界坐标
rigidbody.velocity = origin.TransformVector((device.velocity*5));
rigidbody.angularVelocity = origin.TransformVector((device.angularVelocity*5));
}
else
{
//设置速度
rigidbody.velocity = device.velocity;
//设置角速度
rigidbody.angularVelocity = device.angularVelocity;
}
}
void SnyScores()
{
onenumber.text ="1 Point:"+ one;
twonumber.text = "2 Point:" + two;
threenumber.text = "3 Point:" + three;
fournumber.text = "4 Point:" + four;
textTotalScores.text ="Total: "+(one + two + three + four);
numberscores = Convert.ToInt32(one + two + three + four);
//zongfen
scores = numberscores;
lishizuigao = scores;
}
}
VR 游戏本地存档
最新推荐文章于 2023-08-25 17:17:48 发布