forked from abhinavhinger12/VR-tour-CSE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewBehaviourScript.cs
45 lines (34 loc) · 1003 Bytes
/
NewBehaviourScript.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject Asphalt;
public GameObject Sidewalk;
public GameObject Steps;
private bool walking = false;
private Vector3 spawnPoint;
// Use this for initialization
void Start () {
spawnPoint = transform.position;
}
// Update is called once per frame
void Update () {
if (walking)
{
transform.position = transform.position + Camera.main.transform.forward* 3 * Time.deltaTime;
}
if (transform.position.y < -30f) {
transform.position = spawnPoint;
}
Ray ray = Camera.main.ViewportPointToRay (new Vector3 (.5f, .5f, 0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
if (hit.collider.name.Contains ("Asphalt") || hit.collider.name.Contains ("Sidewalk") || hit.collider.name.Contains ("Steps")) {
walking = true;
}
else {
walking = false;
}
}
}
}