I’m working on a google cardboard VR game. Unlike other cardboard viewers with the magnet slide thing, my viewer (I believe it is a Homido Grab) has a button that extends a small stylus onto the screen. But despite reading a bunch of tutorials I can’t find a method to just “touch screen, go forward” I’m not interested in dragging or anything since it’s a VR thing so there can’t be dragging.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float speed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {
rb.AddForce (transform.forward * speed);
}
else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){
rb.velocity = Vector3.zero;
}
}
}
So to recap, what I want the code to do is make me go in the direction I’m looking when I hold down the button on the headset (which just touches the screen) At the moment the code seems to do nothing. I set up the Google VR demo on my phone and the button worked just fine for that, but the code was too complex form me to understand.