Search Unity

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:
    9,428
    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?