-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayerController.cs
More file actions
154 lines (136 loc) · 4.7 KB
/
playerController.cs
File metadata and controls
154 lines (136 loc) · 4.7 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Google.XR.Cardboard;
using UnityEngine.XR;
using UnityEngine.XR.Management;
public class playerController : MonoBehaviour
{
public GameObject mainCam;
public GameObject stickFire;
public GameObject text1;
public GameObject text2;
public GameObject text3;
public GameObject interactText;
public Light playerPointLight;
Vector3 hitPos;
//public GameObject sample;
bool looksAtGround = false;
bool looksAtFire = false;
bool looksAtCandle = false;
float speed = 4f;
float yOffset = 3f;
// Start is called before the first frame update
void Start()
{
EnterVR();
}
// FixedUpdate is preferred for physics-based calculations
// It runs on regular intervals and may be called more frequently than Update
void FixedUpdate()
{
RaycastHit hit;
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(mainCam.transform.position, mainCam.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
{
Debug.DrawRay(mainCam.transform.position, mainCam.transform.TransformDirection(Vector3.forward) * hit.distance, Color.green);
Debug.Log("Did Hit");
if(hit.transform.gameObject.CompareTag("Fire") && hit.distance < 10f)
{
looksAtGround = false;
looksAtFire = true;
looksAtCandle = false;
}
else if(hit.transform.gameObject.CompareTag("Ground"))
{
looksAtGround = true;
looksAtFire = false;
looksAtCandle = false;
Debug.Log("Hit the Ground!!");
hitPos = hit.point;
}
else if(hit.transform.gameObject.CompareTag("candle") && hit.distance < 10f){
looksAtGround = false;
looksAtFire = false;
looksAtCandle = true;
}
else{
looksAtGround = false;
looksAtFire = false;
looksAtCandle = false;
}
}
else
{
looksAtGround = false;
looksAtFire = false;
looksAtCandle = false;
Debug.DrawRay(mainCam.transform.position, mainCam.transform.TransformDirection(Vector3.forward) * 1000, Color.red);
Debug.Log("Did not Hit");
}
}
// Update is called once per frame
void Update()
{
//Debug.Log("Check");
if(Input.touchCount > 0){
if(looksAtGround){
float step = speed * Time.deltaTime;
Vector3 targetPoint = new Vector3(hitPos.x, hitPos.y + yOffset, hitPos.z);
transform.position = Vector3.MoveTowards(transform.position, targetPoint, step);
}
else if(looksAtFire && !stickFire.activeSelf){
stickFire.SetActive(true);
playerPointLight.enabled = false;
text1.SetActive(false);
text2.SetActive(true);
interactText.SetActive(false);
}
else if(looksAtCandle){
text2.SetActive(false);
text3.SetActive(true);
}
}
}
/// <summary>
/// Enters VR mode.
/// </summary>
private void EnterVR()
{
StartCoroutine(StartXR());
if (Api.HasNewDeviceParams())
{
Api.ReloadDeviceParams();
}
}
/// <summary>
/// Initializes and starts the Cardboard XR plugin.
/// See https://docs.unity3d.com/Packages/com.unity.xr.management@3.2/manual/index.html.
/// </summary>
///
/// <returns>
/// Returns result value of <c>InitializeLoader</c> method from the XR General Settings Manager.
/// </returns>
private IEnumerator StartXR()
{
Debug.Log("Initializing XR...");
yield return XRGeneralSettings.Instance.Manager.InitializeLoader();
if (XRGeneralSettings.Instance.Manager.activeLoader == null)
{
Debug.LogError("Initializing XR Failed.");
}
else
{
Debug.Log("XR initialized.");
Debug.Log("Starting XR...");
XRGeneralSettings.Instance.Manager.StartSubsystems();
Debug.Log("XR started.");
}
}
/*
public void Interact()
{
Debug.Log("Interact pls :)");
}
*/
}