66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using HTC.UnityPlugin.Vive;
|
|
|
|
public class Car : MonoBehaviour
|
|
{
|
|
public bool ifAllowDrive;
|
|
Rigidbody Rigi;
|
|
public AudioSource Aud_Engine;
|
|
public Vector2 V2 = Vector2.zero;
|
|
public float Speed_Run;
|
|
void Start()
|
|
{
|
|
Rigi = transform.GetComponent<Rigidbody>();
|
|
}
|
|
public Transform Wheel_Front_1, Wheel_Front_2;
|
|
public Transform Wheel_Back_1, Wheel_Back_2;
|
|
Quaternion Qua;
|
|
Vector3 RotV3=Vector3 .zero ;
|
|
void OnGUI()
|
|
{
|
|
if (ifAllowDrive)
|
|
{
|
|
V2 = ViveInput.GetPadTouchAxis(HandRole.LeftHand);
|
|
//操作
|
|
if (V2.x == 0 && V2.y == 0)//静止
|
|
{
|
|
Rigi.velocity = Vector3.zero;
|
|
Aud_Engine.Stop();
|
|
}
|
|
else
|
|
{
|
|
if (!Aud_Engine.isPlaying)
|
|
Aud_Engine.Play();
|
|
//车辆转向
|
|
if (V2.x != 0)
|
|
{
|
|
transform.Rotate(0, V2.x * 0.1f, 0, Space.Self);
|
|
//
|
|
//RotV3 = Wheel_Front_1.localRotation.eulerAngles;
|
|
//RotV3.y = V2.x * 90 + 180;
|
|
//if (RotV3.y >210)
|
|
// RotV3.y = 210;
|
|
//if (RotV3.y <150)
|
|
// RotV3.y = 150;
|
|
//Qua.eulerAngles = RotV3;
|
|
//Wheel_Front_1.localRotation = Quaternion.Lerp(Wheel_Front_1.localRotation, Qua, 0.01f);
|
|
//Wheel_Front_2.localRotation = Wheel_Front_1.localRotation;
|
|
}
|
|
if (V2.y != 0)//前后行驶
|
|
{
|
|
transform.Translate(0, 0, V2.y * Speed_Run, Space.Self);
|
|
Wheel_Front_1.Rotate(-V2.y * 2, 0, 0, Space.Self);
|
|
Wheel_Front_2.Rotate(-V2.y * 2, 0, 0, Space.Self);
|
|
Wheel_Back_1.Rotate(-V2.y * 2, 0, 0, Space.Self);
|
|
Wheel_Back_2.Rotate(-V2.y * 2, 0, 0, Space.Self);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
Aud_Engine.Stop();
|
|
}
|
|
}
|