Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    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,785
    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?