Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Activate Trigger When in Trigger

Discussion in 'Scripting' started by TheWittyRobin, Oct 13, 2018.

  1. TheWittyRobin

    TheWittyRobin

    Joined:
    Aug 18, 2018
    Posts:
    36
    Currently trying to figure out how to transition between scenes smoothly and trying to use a "E" to activate system but for some reason it only works when approaching the scene.load trigger. So in short i con only hold E while approaching it not while I'm actually in the trigger which is what I'm wanting. Any suggestions?


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class LevelManager : MonoBehaviour
    7. {
    8.     private void OnTriggerEnter(Collider sceneTrigger)
    9.     {   if (Input.GetKey(KeyCode.E))
    10.         if (sceneTrigger.CompareTag("Player"))
    11.             {
    12.             SceneManager.LoadScene("inside basement 1", LoadSceneMode.Single);
    13.             SceneManager.UnloadSceneAsync("a mans modified unknown");
    14.             }
    15.     }
    16. }
    17.  
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    4,949
    try OnTriggerStay()
    because OnTriggerEnter() will only run once, so you cannot really do keyboard polling there. (it doesnt loop)
     
  3. TheWittyRobin

    TheWittyRobin

    Joined:
    Aug 18, 2018
    Posts:
    36
    okay see that's what i thought it was but it just wasn't working. Any ideas on a player position saver for in between scenes?