forked from UnityTutorialsHD/Unity-Tutorial-Assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnterVehicle.cs
53 lines (49 loc) · 1.39 KB
/
EnterVehicle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Vehicles.Car;
public class EnterVehicle : MonoBehaviour
{
private bool inVehicle = false;
CarUserControl vehicleScript;
public GameObject guiObj;
GameObject player;
void Start()
{
vehicleScript = GetComponent<CarUserControl>();
player = GameObject.FindWithTag("Player");
guiObj.SetActive(false);
}
// Update is called once per frame
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player" && inVehicle == false)
{
guiObj.SetActive(true);
if (Input.GetKey(KeyCode.E))
{
guiObj.SetActive(false);
player.transform.parent = gameObject.transform;
vehicleScript.enabled = true;
player.SetActive(false);
inVehicle = true;
}
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
guiObj.SetActive(false);
}
}
void Update()
{
if (inVehicle == true && Input.GetKey(KeyCode.F))
{
vehicleScript.enabled = false;
player.SetActive(true);
player.transform.parent = null;
inVehicle = false;
}
}
}