"Fading out and triggering the load of the next scene is not functioning properly following the recent update

After updating my storybook app, I encountered a problem with a function that no longer works. The script on the gameobject containing my audio track used to fade the screen to black and load the next scene when the audio track ended.

I'm an artist who cobbled together this script years ago with the help of some forum users - can someone guide me on how to fix it? I suspect that some syntax has become obsolete or something similar?

The fading out and level loading work fine when I press the "page turn" button in the app, but the issue seems to be specifically related to the audio triggering the end event.

It appears that the script is stuck in the while loop:

function Start()
{
     Screen.sleepTimeout = 0.0f;    // disable auto-dimming
     PlayAudio();
}

function PlayAudio()
{
     GetComponent.<AudioSource>().Play();
     while(GetComponent.<AudioSource>().time < GetComponent.<AudioSource>().clip.length){
          yield; //do nothing if the audio is still playing
     }
     //once the audio stops, proceed to load the level

    if(AdventManager.AdventMode)
    {
        // Half-fade the scene in Advent mode
        GetComponent.<Renderer>().enabled = true;

           Fade.use.Alpha(GetComponent.<Renderer>().material, 0.0, 0.0, 0.0);

        Fade.use.Alpha(GetComponent.<Renderer>().material, 0.0, 0.5, 0.5);

        yield WaitForSeconds(0.5);

        // Show back/forward/rewind buttons
        var fwd : GameObject = GameObject.Find("BTN_Fwd");
        var back : GameObject = GameObject.Find("BTN_Back");
        var reload : GameObject = GameObject.Find("BTN_Reload");
        Fade.use.Alpha(fwd.GetComponent.<Renderer>().material, 0.0, 1.0, 0.0);
        Fade.use.Alpha(back.GetComponent.<Renderer>().material, 0.0, 1.0, 0.0);
        Fade.use.Alpha(reload.GetComponent.<Renderer>().material, 0.0, 1.0, 0.0);
    }
    else
    {
        // Fade to black
        GetComponent.<Renderer>().enabled = true;

        Fade.use.Alpha(GetComponent.<Renderer>().material, 0.0, 0.0, 0.0);

        Fade.use.Alpha(GetComponent.<Renderer>().material, 0.0, 1.0, 0.8);

        yield WaitForSeconds(0.8);

        // Go to the next page
        Application.LoadLevel (Application.loadedLevel+1);
    }

}

Answer №1

Consider replacing the following section of code with the suggested alternative:

while(GetComponent.<AudioSource>().time < GetComponent.<AudioSource>().clip.length){
              yield; //if the audio is playing, don't do anything
}

Here is the recommended replacement:

yield WaitForSeconds(GetComponent.<AudioSource>().clip.length);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating dynamic input fields on button click in AngularJS: Step-by-step guide

Currently, I am working on a project that involves a dropdown menu. Here is a sneak peek: https://i.sstatic.net/ghwr8.jpg In the dropdown menu, users are able to select from various input types such as TextBox, Checkbox, Radio button, and Drop down. Addi ...

Provide solely the specified content range

While working with Node.js, my goal is to develop a video server that can serve a specific portion of a larger media file. Thanks to this gist, I have successfully created a video server and integrated it with an HTML5 video player using: <video contr ...

Styling Elements with CSS Containers

Currently, I am going through a web development project on YouTube where I am constructing a JavaScript clock. It seems that by creating a container and a child element, I can use absolute and relative positioning. However, one thing that confuses me is w ...

The never-ending cycle and memory overload that occur when using Angular's ngRoute

It seems like I may have hit a roadblock while attempting to get ng-view and ngRoute up and running. Everything appeared to be functioning correctly, but it looks like the entire process is caught in a loop. Just to provide some context, I am working with ...

I currently have an array of strings and wish to print only the lines that include a specific substring

Here i want to showcase lines that contain the following strings: Object.< anonymous > These are multiple lines: Discover those lines that have the substring Object . < anonymous > Error: ER_ACCESS_DENIED_ERROR: Access denied for user ' ...

Touch screen scrolling has been observed to significantly reduce the speed of AJAX downloads in Chrome

There is an unusual issue I am experiencing with an AJAX request that hangs intermittently when scrolling with a finger on a touch-enabled device. The problem occurs as long as the finger is held down while scrolling. It's difficult to explain the pro ...

Consistent outcomes with PHP AJAX

Currently in the process of verifying if the email is already being used (for a password reset). Here is the JavaScript code: //Verification of email existence $(document).ready(function() { //Listening for input in the email field $("#email").keyup(funct ...

Completely charting the dimensions of an unfamiliar object (and the most effective method for determining its extent)

I am facing a challenge with a "parent" object that contains an unknown number of children at various depths. My main objective is to efficiently map this "parent" object and all its levels of children. How can I achieve this task? Each child already inc ...

Steps to ensure that a particular tab is opened when the button is clicked from a different page

When I have 3 tabs on the register.html page, and try to click a button from index.html, I want the respective tab to be displayed. Register.html <ul class="nav nav-tabs nav-justified" id="myTab" role="tablist"> <l ...

Remove an item from an array using $pull, and also remove any corresponding references from another array

Imagine this scenario within a database of clients: client: { services: [ { _id: 111, someField: 'someVal' }, { _id: 222, someField: 'someVal' } ... // More services ] staff: [ { ...

The react-bootstrap implementation is not functioning as expected, resulting in an unsupported server component error

Having an issue with an Unsupported Server Component Error while using react-bootstrap with typescript. I've shared the contents of my page.tsx file, layout.tsx file, and the specific error message. layout.tsx file import type { Metadata } from &apos ...

Guide to redirecting all Angular requests to index.html using Nginx

I've configured my Nginx server to serve an Angular app with a simple config file like so: server { listen 80; listen [::]:80; root /path/to/apps/myapp/current/dist; access_log /path/to/apps/myapp/current/log/nginx.access.log; error_log /p ...

Errors of various kinds are occurring in Webpack during the npm install process

Whenever I execute npm install or npm ci, it triggers a webpack build that generates a plethora of incorrect errors. These errors allude to missing dependencies that are actually present. Interestingly, running npm ci seems to produce more errors than npm ...

Struggling to integrate Karma and Jasmine into my Angular controller setup

After numerous attempts and hours of troubleshooting, I am still unable to successfully integrate Karma with my Angular controller. No matter what I try, the same error persists even when removing expectGET() calls - as soon as $http.flush(); is called. A ...

Discover the most effective method for identifying duplicate items within an array

I'm currently working with angular4 and facing a challenge of displaying a list containing only unique values. Whenever I access an API, it returns an array from which I have to filter out repeated data. The API will be accessed periodically, and the ...

Mapping memory for FirefoxOS is like equivalent strides

Is there a way to create a memory mapped file in FirefoxOS, Tizen or other pure-JS mobile solutions? In the scenario of a mobile browser where you have large amounts of data that can't fit in RAM or you prefer not to load it all at once to conserve R ...

Locate integer and add a decimal point followed by two zeros

I want to add .00 to a number if it is not already a decimal. However, the code I am using below seems to be converting the entire number to 0.00 instead of just appending .00 at the end. For instance, if the number is 12,200, it ends up as 0.00 after appl ...

Ensuring that the empty bubble remains undisturbed, here's a guide on effectively implementing the if

I need assistance with adding an "if condition" to my text field. The condition should prevent the empty bubble from appearing when the send button is clicked. function verifyInput(){ var currentText = document.getElementById("demo").innerHTML; var x ...

Exploring the Concept of Callbacks in JavaScript

What happens behind the scenes when a function is passed as a parameter in JavaScript and how does the engine recognize it as a callback? ...

JavaScript implementation for universal zoom functionality across all web browsers

I am working on a graph created with simple <div> elements and I am looking for a way to allow users to zoom in and out. It appears that the css zoom property, which is effective in Internet Explorer, does not work well or consistently in other brows ...