Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. 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:
    58
    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:
    274
    This doesn't make any sense on it's own. There is no skipping logic in what you have shown.