78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
|
|
public class ChaChe : MonoBehaviour
|
|
{
|
|
public Transform VrTrans, VrCamTrans,DriverPosTrans,ControlTrans;
|
|
public int StepValue;
|
|
public float Rot;
|
|
//开车参数
|
|
float CarSpeed, SetSpeed;
|
|
//轮子
|
|
public Transform WheelTrans_1, WheelTrans_2, WheelTrans_3, WheelTrans_4;
|
|
//
|
|
public Text DebugText;
|
|
Vector3 V3_Inner;
|
|
public AudioSource Aud_Run;
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
public void StartSetControl()
|
|
{
|
|
Invoke("SetControl", 1.5f);
|
|
}
|
|
public void SetControl()
|
|
{
|
|
VrTrans.parent = transform;
|
|
Debug.Log("前"+VrTrans.position.ToString());
|
|
V3_Inner = VrCamTrans.position - VrTrans.position;//内部位置差
|
|
Debug.Log(V3_Inner.ToString());
|
|
VrTrans.position = DriverPosTrans.position - V3_Inner;
|
|
}
|
|
public Transform YY_XiaoBi_In, YY_XiaoBi_Out;//液压及外套
|
|
void Update()
|
|
{
|
|
//液压缸朝向
|
|
YY_XiaoBi_In.LookAt(YY_XiaoBi_Out);
|
|
YY_XiaoBi_Out.LookAt(YY_XiaoBi_In);
|
|
Drive();
|
|
}
|
|
void Drive()
|
|
{
|
|
//档位基本速度
|
|
switch (StepValue)
|
|
{
|
|
case -1: //倒挡
|
|
CarSpeed = -30;
|
|
if (!Aud_Run.isPlaying)
|
|
Aud_Run.Play();
|
|
break;
|
|
case 0: //空挡
|
|
CarSpeed = 0;
|
|
if (Aud_Run.isPlaying)
|
|
Aud_Run.Stop();
|
|
break;
|
|
case 1://1档
|
|
CarSpeed = 30;
|
|
if (!Aud_Run.isPlaying)
|
|
Aud_Run.Play();
|
|
break;
|
|
}
|
|
//行进
|
|
SetSpeed = Mathf.Lerp(SetSpeed, CarSpeed, 0.3f);
|
|
//Rot = MapCon .value- 0.5f;
|
|
DebugText.text ="角度" + Rot.ToString();
|
|
if (SetSpeed != 0)
|
|
{
|
|
transform.Translate(0, 0, SetSpeed * 0.0001f, Space.Self);
|
|
transform.Rotate(Vector3.up, Rot * 0.5f, Space.Self);
|
|
WheelTrans_1.Rotate(Vector3.left, SetSpeed * 0.01f);
|
|
WheelTrans_2.Rotate(Vector3.left, SetSpeed * 0.01f);
|
|
WheelTrans_3.Rotate(Vector3.left, SetSpeed * 0.01f);
|
|
WheelTrans_4.Rotate(Vector3.left, SetSpeed * 0.01f);
|
|
}
|
|
}
|
|
}
|