using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hand_trigger : MonoBehaviour {
SteamVR_TrackedObject trackobj;
SteamVR_Controller.Device device;
public GameObject sphere;
//把手
public GameObject jiaobanji;
//角度变量
private float number;
//观测的物体
public GameObject cube_;
private float timeone;
private float timetwo;
private float timejishi;
//speed
private float aaa=1;
Quaternion v;
// Use this for initialization
void Start () {
trackobj = transform.GetComponent<SteamVR_TrackedObject>();
}
private void FixedUpdate()
{
}
// Update is called once per frame
void Update () {
try
{
device = SteamVR_Controller.Input((int)trackobj.index);
}
catch (System.Exception)
{
throw;
}
}
private void OnTriggerStay(Collider other)
{
if (other.name == "gan")
{
if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
{
//sphere与摇杆轴在一个面上&&当一直接触时 sphere的除面上坐标 其他与手柄坐标一致(我这里是x轴)
sphere.transform.position = new Vector3(sphere.transform.position.x, transform.position.y, transform.position.z);
//判断前后y值
timejishi += Time.deltaTime;
if (timejishi <0.02f)
{
timeone = sphere.transform.position.y;
print("1" + timeone);
}
if(timejishi>0.02f&& timejishi<0.04f)
{
timetwo = sphere.transform.position.y;
print("2" + timetwo);
}
if (timejishi > 0.04f)
{
timejishi -= 0.04f;
}
//分界线
if (sphere.transform.position.z > 0.7)
{
number = 0;
if (timetwo - timeone <0f)
{
//上升;
cube_.transform.Translate(Vector3.up * Mathf.Abs(timetwo - timeone) * aaa);
//cube_.transform.position =Vector3.Lerp(cube_.transform.position,new Vector3 (1, 1 +Mathf.Abs(timetwo - timeone) * aaa, 0.5f),1*Time.deltaTime);
print("上升");
}
else
{
//下降;
cube_.transform.Translate(Vector3.down * Mathf.Abs(timetwo - timeone) * aaa);
//cube_.transform.position = Vector3.Lerp(cube_.transform.position, new Vector3(1, 1 - Mathf.Abs(timetwo - timeone) * aaa, 0.5f), 1 * Time.deltaTime);
print("下降");
}
}
//分界线
if (sphere.transform.position.z <= 0.7)
{
number = -1;
if (timetwo - timeone < 0)
{
//下降;
cube_.transform.Translate(Vector3.down * Mathf.Abs(timetwo - timeone) * aaa);
//cube_.transform.position = Vector3.Lerp(cube_.transform.position, new Vector3(1, 1 - Mathf.Abs(timetwo - timeone) * aaa, 0.5f), 1 * Time.deltaTime);
print("下降");
}
else
{
//上升;
cube_.transform.Translate(Vector3.up * Mathf.Abs(timetwo - timeone) * aaa);
//cube_.transform.position = Vector3.Lerp(cube_.transform.position, new Vector3(1, 1 + Mathf.Abs(timetwo - timeone) * aaa, 0.5f), 1 * Time.deltaTime);
print("上升");
}
}
print("cha值"+Mathf.Abs(timetwo - timeone));
//核心 z轴朝向sphere
other.transform.LookAt(sphere.transform);
//角度自测在y轴会出现自旋转 需手动调角度 number为z轴变换角度变量
other.transform.localEulerAngles = new Vector3(other.transform.localEulerAngles.x, other.transform.localEulerAngles.y,180*number);
}
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
{
timejishi = 0f;
}
}
}
}
“手摇” 搅拌机
猜你喜欢
转载自blog.csdn.net/fanfan_hongyun/article/details/80995476
今日推荐
周排行