Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

trying to change scene by grabbing door handle

Discussion in 'Scripting' started by ryjoe1312, Jan 3, 2020.

  1. ryjoe1312

    ryjoe1312

    Joined:
    Dec 3, 2019
    Posts:
    4
    UPDATE Below


    1 using System.Collections;
    2 using System.Collections.Generic;
    3 using UnityEngine;
    4 using UnityEngine.SceneManagement;
    5
    6
    7 public class ToShowRoom : MonoBehaviour
    8 {
    9
    10 void Update()
    11 {
    12 if (OVRInput.GetDown(OVRInput.Axis1D.PrimaryHandTrigger))
    13 {
    14 SceneManager.LoadScene(1);
    15 }
    16
    17 }
    18 }

    this is my code I am trying to grab a door handle to change scenes. on the door handle i have a box collider that "Is Trigger"

    My character is using the OVRPlayercontroller.

    i am getting this error, I am new to coding and do not understand whats wrong.
    Assets\ToShowRoom.cs(12,30): error CS1503: Argument 1: cannot convert from 'OVRInput.Axis1D' to 'OVRInput.Button'

    thanks for the help
     
    Last edited: Jan 3, 2020
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
  3. ryjoe1312

    ryjoe1312

    Joined:
    Dec 3, 2019
    Posts:
    4
    I changed the "if (OVRInput.GetDown(OVRInput.Axis1D.PrimaryHandTrigger))" to "if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger))"

    and then got this error
    Assets\ToShowRoom.cs(13,13): error CS0029: Cannot implicitly convert type 'float' to 'bool'
     
  4. ryjoe1312

    ryjoe1312

    Joined:
    Dec 3, 2019
    Posts:
    4
    I have changed my code and it works now the only problem is that I think because it is coming back true it is constantly jumping back and forth between the scenes. I have box colliders on the door handles but i don't know how to link the script to that collider.

    1 using System.Collections;
    2 using System.Collections.Generic;
    3 using UnityEngine;
    4 using UnityEngine.SceneManagement;
    5
    6
    7 public class ToShowRoom : MonoBehaviour
    8 {
    9
    10 void Update()
    11
    12 {
    13
    14 OVRInput.Get(OVRInput.RawAxis1D.LHandTrigger);
    15 if (true)
    16 {
    17 SceneManager.LoadScene(1);
    18 }
    19
    20
    21 }
    22 }

    I made another code for the other scene same as this but it is LoadScene(0) which is why I think it is jumping back and forth
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    Umm...you're not checking for the input. You're just checking if(true), so it's always true...

    You need to check if the OverInput.Get is returning true or false.

    And you may need an additional check if you are touching the door handle or not.