Search Unity

Scripting for looking at an object long enough to trigger an event.

Discussion in 'Scripting' started by drewnashty1937, Oct 13, 2015.

  1. drewnashty1937

    drewnashty1937

    Joined:
    Jun 29, 2015
    Posts:
    4
    I'm not real familiar with the lingo for scripting and i'm sure if I knew the correct word to search for I would find what I'm looking for. What is the language that will trigger an event after you look at the object for a few seconds?

    I'm trying to create a Gear VR Drive in theater and when you look at the theater screen for like 3 seconds it will load a full screen video. I read that you can't have a movieTexture in a VR environment in Unity so I figured I'd just make it load a new scene where the movie is in full screen.
     
  2. drewnashty1937

    drewnashty1937

    Joined:
    Jun 29, 2015
    Posts:
    4
    So I think I may have found what I am looking for but I need some help tailoring it to OVR Camera as I'm getting a "NullReferenceException Object reference not set to an instance of an object" error. And I think it's because I'm not using the standard MainCamera.

    Created a JS with:

    Code (csharp):
    1. #pragma strict
    2. //Type the name of the scene to load in the inspector.
    3.  
    4. var MovieTestScene : String ;
    5.  
    6. var hit: RaycastHit;
    7.  
    8. function Update (){
    9.  
    10. var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    11.  
    12. if (Input.GetMouseButtonDown(0)){
    13.  
    14. if (Physics.Raycast (ray, hit , Mathf.Infinity)){
    15.  
    16. if (hit.collider.name == "ViewScreen") { Application.LoadLevel(MovieTestScene); }
    17.  
    18. } } }
    So the Console error points to line 10 which is:

    var ray = Camera.main.ScreenPointToRay ...

    What do I need to change in here to reference the Camera of the OVRPlayerController, I tried changing "Camera" and "main" to OVRPlayerController and OVR CameraRig but that didn't fix it