210 lines
7.7 KiB
C#
210 lines
7.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Exper_2 : MonoBehaviour {
|
|
public Car CarCon;
|
|
public Transform Trans_CC, Trans_Vr, Trans_VrCam, Trans_DriverPos, Trans_PlayBack;
|
|
public Animator CarAni, CarAni_UD;
|
|
public GameObject Role_Driver;//驾驶员
|
|
public GameObject UI_GetConfirm, UI_End;
|
|
public GameObject Control_Xiao, Control_Da;//操控
|
|
public DaBi XiaoBiCon;
|
|
public GameObject Obj_ShowDis;//转场
|
|
public GameObject Hold_World,Hold_Self, Cargo_World, Cargo_Self;//货物
|
|
public Transform Pos_1, Pos_2, Pos_3;
|
|
public GameObject Arrow_1, Arrow_2, Arrow_3, Arrow_4;
|
|
bool ifRun = false;
|
|
public int Step = 0;
|
|
public AudioSource Aud_1, Aud_2, Aud_3, Aud_4;
|
|
public AudioSource Aud_Correct;
|
|
//
|
|
float Dis;
|
|
|
|
void Start()
|
|
{
|
|
//叉车位置
|
|
Trans_CC.position = new Vector3(13.67f, 0.838f, -16.42f);
|
|
Trans_CC.rotation = Quaternion.Euler(0, 0, 0);
|
|
}
|
|
public void ShowObj_World()
|
|
{
|
|
//交互物
|
|
Hold_World.SetActive(true);
|
|
Cargo_World.SetActive(true);
|
|
}
|
|
void Update()
|
|
{
|
|
if (ifRun)
|
|
StartExper();
|
|
}
|
|
public void StartRun()
|
|
{
|
|
Invoke("Run", 2);
|
|
}
|
|
float dTime;
|
|
void Run()
|
|
{
|
|
ifFirst = true;
|
|
ifRun = true;
|
|
Step++;
|
|
}
|
|
//设置驾驶位
|
|
Vector3 V3_Inner;
|
|
public void SetControl()
|
|
{
|
|
Trans_Vr.parent = Trans_CC;
|
|
V3_Inner = Trans_VrCam.position - Trans_Vr.position;//内部位置差
|
|
Trans_Vr.position = Trans_DriverPos.position - V3_Inner;
|
|
}
|
|
// Update is called once per frame
|
|
bool ifFirst;
|
|
void StartExper()
|
|
{
|
|
if (ifRun)
|
|
{
|
|
switch (Step)
|
|
{
|
|
case 1://提示到达驾驶位
|
|
if (ifFirst)
|
|
{
|
|
Aud_1.Play();
|
|
ifFirst = false;
|
|
Arrow_1.SetActive(true);//箭头
|
|
Pos_1.gameObject.SetActive(true);//目标光圈
|
|
}
|
|
Dis = Mathf.Abs(Trans_VrCam.position.x - Pos_1.position.x) + Mathf.Abs(Trans_VrCam.position.z - Pos_1.position.z);
|
|
if (Dis < 1)//进入驾驶位
|
|
{
|
|
Aud_Correct.Play();
|
|
Aud_1.Stop();
|
|
Arrow_1.SetActive(false);//箭头
|
|
Pos_1.gameObject.SetActive(false);//目标光圈
|
|
ifRun = false;
|
|
Obj_ShowDis.SetActive(true);//转场
|
|
Invoke("Run", 2);
|
|
}
|
|
break;
|
|
case 2://提示到达取货位
|
|
if (ifFirst)
|
|
{
|
|
CarCon.ifAllowDrive = true;
|
|
Aud_2.Play();
|
|
ifFirst = false;
|
|
Arrow_2.SetActive(true);//箭头
|
|
Pos_2.gameObject.SetActive(true);//目标光圈
|
|
SetControl();//设置驾驶视角
|
|
}
|
|
Dis = Mathf.Abs(Trans_VrCam.position.x - Pos_2.position.x) + Mathf.Abs(Trans_VrCam.position.z - Pos_2.position.z);
|
|
if (Dis < 1.5f)
|
|
{
|
|
Aud_Correct.Play();
|
|
Aud_2.Stop();
|
|
Arrow_2.SetActive(false);//箭头
|
|
Pos_2.gameObject.SetActive(false);//目标光圈
|
|
ifRun = false;
|
|
Obj_ShowDis.SetActive(true);//转场
|
|
Invoke("Run", 2);
|
|
}
|
|
break;
|
|
case 3://提示叉货
|
|
if (ifFirst)
|
|
{
|
|
Aud_3.Play();
|
|
ifFirst = false;
|
|
ifRun = false;
|
|
Arrow_3.SetActive(true);
|
|
//车辆复位
|
|
Trans_CC.position = new Vector3(3.93f, Trans_CC.position.y, 5.25f);
|
|
Trans_CC.rotation = Quaternion.Euler(0, -90, 0);
|
|
SetControl();//设置驾驶视角
|
|
UI_GetConfirm.SetActive(true);//叉货完成UI
|
|
}
|
|
break;
|
|
case 4://提示运输
|
|
if (ifFirst)
|
|
{
|
|
Aud_3.Stop();
|
|
Aud_4.Play();
|
|
ifFirst = false;
|
|
Arrow_3.SetActive(false);
|
|
Arrow_4.SetActive(true);//线路
|
|
//车辆复位
|
|
Trans_CC.position = new Vector3(2.11f, Trans_CC.position.y, 8);
|
|
Trans_CC.rotation = Quaternion.Euler(0, -180, 0);
|
|
SetControl();//设置驾驶视角
|
|
Cargo_World.SetActive(false);
|
|
Hold_World.SetActive(false);
|
|
Cargo_Self.SetActive(true);
|
|
Hold_Self.SetActive(true);
|
|
CarAni_UD.SetFloat("Blend", 0.34f);
|
|
Control_Xiao.SetActive(false);//禁止操控大小臂
|
|
Control_Da.SetActive(false);
|
|
XiaoBiCon.Kind = 0;
|
|
}
|
|
Dis = Mathf.Abs(Trans_VrCam.position.x - Pos_3.position.x) + Mathf.Abs(Trans_VrCam.position.z - Pos_3.position.z);
|
|
if (Dis < 2)
|
|
{
|
|
Aud_4.Stop();
|
|
Arrow_4.SetActive(false);//箭头
|
|
CarAni.enabled = true;//事故动画
|
|
CarAni.SetInteger ("Kind", 2);
|
|
Step = 5;
|
|
ifFirst = true;
|
|
CarCon.ifAllowDrive = false;
|
|
}
|
|
break;
|
|
case 5://事故动画阶段
|
|
SetControl();//设置驾驶视角
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
dTime = Time.time;
|
|
}
|
|
if (Time.time - dTime > 13)
|
|
{
|
|
Step = 6;
|
|
}
|
|
break;
|
|
case 6://转场
|
|
Obj_ShowDis.SetActive(true);//转场
|
|
ifRun = false;
|
|
Invoke("Run", 2);
|
|
break;
|
|
case 7://事故回放准备
|
|
ifRun = false;
|
|
CarAni.SetInteger("Kind", 0);
|
|
Role_Driver.SetActive(true);
|
|
Cargo_Self.SetActive(true);
|
|
Trans_Vr.parent = null;
|
|
Trans_Vr.position = Trans_PlayBack.position;
|
|
Invoke("Run", 2);
|
|
break;
|
|
case 8://回放进行
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
CarAni.SetInteger("Kind", 2);
|
|
ifRun = false;
|
|
Invoke("Run", 12);
|
|
}
|
|
break;
|
|
case 9://事故分析及答题
|
|
if (ifFirst)
|
|
{
|
|
ifFirst = false;
|
|
Trans_Vr.position = new Vector3(3.66f, 0.67f, -8);
|
|
Trans_CC.gameObject.SetActive(false);//叉车隐藏
|
|
UI_End.SetActive(true);
|
|
ifRun = false;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
public void Exit()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|