Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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,693
    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?