Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Virtual Reality VR in Unity VR Setup HTC Vive Setup

Harrison Bolin
Harrison Bolin
3,975 Points

I'm getting an error trying to run the project at this point

When I run the game for the first time, I get the following error:

Assets/Scripts/VRAdjustment.cs(30,31): error CS0029: Cannot implicitly convert type UnityEngine.Vector3' toUnityEngine.Quaternion'

using UnityEngine;
using System.Collections;
using UnityEngine.VR;

public class VRAdjustment : MonoBehaviour {

    private Vector3 monitorRotation = new Vector3 (-12f, 0f, 0f);
    private Vector3 openVRPosition = new Vector3 (0f, -1.75f, 0f);


    // Use this for initialization
    void Awake () {

        // If there is no VR device at the start of the game:
        if (!VRDevice.isPresent) {

            //tilt camera upward for monitor view
            transform.localRotation = Quaternion.Euler (monitorRotation);

        } else {

            //Otherwise, if VR Device available and is OpenVR
            if (VRSettings.loadedDeviceName == "OpenVR") {

                //Then move camera to floor
                transform.localRotation = openVRPosition;
            }

        }
    }

    // Update is called once per frame
    void Update () {

        //If reset of camera needed
        if (Input.GetKeyUp (KeyCode.R)) {

            InputTracking.Recenter ();

        }

    }


    void OnApplicationQuit () {

        // When app quit, disable VR
        VRSettings.enabled = false;


    }
 }

That's the code I typed. Is something wrong?

1 Answer

Harrison Bolin
Harrison Bolin
3,975 Points

Found the problem. In line 26, I had written "transform.localRotation" instead of transform.localPosition