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

loading screen system

Discussion in 'Scripting' started by mirkojpn, Jun 14, 2018.

  1. mirkojpn

    mirkojpn

    Joined:
    Mar 31, 2018
    Posts:
    65
    hi everyone.

    i^m working on a door system where when you are in front of a door and you press "M" key on keyboard, you are able to be transformed in another place, and it`s working good, but what i need is a black screen betwenn this.
    open door ---> black screen,play door sound ----> new room.

    what i did is the following code, that works, but with a issues.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DoorSystem : MonoBehaviour {
    6.  
    7.     public Vector3 newPosition;
    8.  
    9.     public Camera from;
    10.    
    11.     public Camera loading;
    12.     public Camera to;
    13.  
    14.     public AudioSource doorSound;
    15.  
    16.     public float waitTime;
    17.  
    18.  
    19.  
    20.  
    21.  
    22.     void Start () {
    23.         doorSound = GetComponent<AudioSource>();
    24.  
    25.     }
    26.  
    27.  
    28.     void OnTriggerStay (Collider other) {
    29.     if(other.CompareTag("Player")&& Input.GetKeyDown(KeyCode.M)) {
    30.         StartCoroutine(loadingScreen());
    31.         other.gameObject.transform.position = newPosition;
    32.  
    33.        
    34.        
    35.        
    36.     }
    37.     }
    38.  
    39.     IEnumerator loadingScreen () {
    40.         from.gameObject.SetActive(false);
    41.         loading.gameObject.SetActive(true);
    42.         doorSound.Play();
    43.         yield return new WaitForSeconds(waitTime);
    44.         loading.gameObject.SetActive(false);
    45.         to.gameObject.SetActive(true);
    46.        
    47.     }
    the problem is, if you press any key this is going to be skipped, and the door sound is still played.

    i want something that allow me to skip the back loading screen, and stop the audioclip, but when i press and specific key.

    someone have any idea to how to do it?
     
  2. whileBreak

    whileBreak

    Joined:
    Aug 28, 2014
    Posts:
    287
    This doesn't make any sense on it's own. There is no skipping logic in what you have shown.