C#
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
[RequireComponent(typeof(CharacterController))]
[RequireComponent(typeof(AudioSource))]
public class VRAutowalk : MonoBehaviour {
public static VRAutowalk instace;
public float speed = 3.0F;
public bool moveForward = false;
private CharacterController controller;
private Transform vrHead;
Rigidbody rbody;
public GameObject bitis;
public GameObject birinci;
public GameObject ikinci;
public GameObject ucuncu;
public GameObject dorduncu;
public AudioClip yanlisses;
public AudioClip dogruses;
public AudioClip sinirlar;
public AudioClip BitisSesi;
AudioSource audioSource;
void Start () {
rbody = GetComponent<Rigidbody> ();
audioSource = GetComponent<AudioSource>();
instace = this;
controller = GetComponent<CharacterController>();
vrHead = Camera.main.transform;
}
void Update () {
if (moveForward) {
Vector3 forward = vrHead.TransformDirection (Vector3.forward);
controller.SimpleMove (forward * speed);
bitis.SetActive (true);
}
}
void OnTriggerEnter (Collider other){
if (other.tag == “DurulacakAlan”) {
moveForward = false;
}
if (other.tag == “bitis”)
{
moveForward = false;
audioSource.PlayOneShot(BitisSesi);
}
if (other.tag == “Sinir”)
{
audioSource.PlayOneShot(sinirlar);
}
if(other.tag == “Yanlis”)
{
audioSource.PlayOneShot(yanlisses);
birinci.SetActive(false);
ikinci.SetActive(true);
}
if (other.tag == “Dogru”)
{
audioSource.PlayOneShot(dogruses);
birinci.SetActive(false);
ikinci.SetActive(true);
}
if (other.tag == “Yanlis2”)
{
audioSource.PlayOneShot(yanlisses);
ikinci.SetActive(false);
ucuncu.SetActive(true);
}
if (other.tag == “Dogru2”)
{
audioSource.PlayOneShot(dogruses);
ikinci.SetActive(false);
ucuncu.SetActive(true);
}
if (other.tag == “Yanlis3”)
{
audioSource.PlayOneShot(yanlisses);
ucuncu.SetActive(false);
dorduncu.SetActive(true);
}
if (other.tag == “Dogru3”)
{
audioSource.PlayOneShot(dogruses);
ucuncu.SetActive(false);
dorduncu.SetActive(true);
}
if (other.tag == “Yanlis4”)
{
audioSource.PlayOneShot(yanlisses);
dorduncu.SetActive(false);
}
if (other.tag == “Dogru4”)
{
audioSource.PlayOneShot(dogruses);
dorduncu.SetActive(false);
}
}
void OnTriggerExit (Collider other){
if (other.tag == “DurulacakAlan”) {
moveForward = true;
}
}
public void ToggleWalk (){
moveForward = !moveForward;
}
}