- Home /
Question by
olykken · Mar 17, 2016 at 10:33 PM ·
camerascripting problemmovementraycast
How to move the main camera in Google Cardboard?
I am working with Google Cardboard and I need to make it so that when the user looks at an object with the tag "End" the main camera will move along a ray toward that object. I have some code but my if statement is a null reference so it doesn't work. below is my code any help would be greatly appreciated.
public class RaycastScript : MonoBehaviour {
public Camera camera;
public float moveSpeed;
// Update is called once per frame
void FixedUpdate () {
// Vector3 fwd = transform.TransformDirection(Vector3.forward);
// Physics.Raycast (transform.position, fwd, 60);
RaycastHit hit;
if (hit.collider.tag == "End") {
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
camera.transform.Translate (ray.direction * moveSpeed, Space.Self);
}
}
}
Comment