Application.LoadLevel()在Unity中有延迟

时间:2016-07-16 20:39:44

标签: c# unity3d

我想问一下,在我的角色死于游戏后是否有可能延迟加载等级。我使用以下代码:

void Update () {
if (health.currentVal <= 0)
    Die ();
}
void Die(){
   Application.LoadLevel (Application.loadedLevel);
}

这基本上重塑了我的场景,但如果可能,我想添加声音和延迟。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

您可以使用Invoke并等待5秒钟。

as.Date("(u'9', u'2005', u'06')", format = "(u'%d', u'%Y', u'%m")
# [1] "2005-06-09"

您也可以使用协同程序

Invoke("Die",5);

然后使用IEnumerator waitRestart() { yield return new WaitForSeconds(5); //Wait for 5 secs Die(); } 调用它。

答案 1 :(得分:0)

使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <!-- Optional theme --> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style1.css"> </head> <body> <div class="container"> <nav class="navbar navbar-default site-nav"> <div class="container"> <div class="navbar-header"> <img id="logo" src="images\\logo.png"> <img id="logo1" src="images\\logo1.jpg"> <label id="content2"> CALL </label> <label id="content3">555-123-4567 </label> </LI> </div> </div> </nav> <div class="row"> <div class="col-md-12 banner-parent"> <div class="banner-background"> <img id="back1" src="images\\back.png"> <hr> </div> <div class="row"> <div class="col-md-3"></div> <div class="col-md-6 text-center banner"> <div class="page-header"> <h3 id="first"><label id="first1"> PROFESSIONAL</label> <label id="first2"> PAINTERS </label> </h3> <h4 id="second"><label id="second1"> OF LARGO,CLEANWATER,TAMPA </label> </H4> </div> <h4 id="content12"> We Care About More Than Paint! </h4> <img src="images\\logo2.jpg" class="logo21"> <form name="myForm" class="form-signin" method="post" action="welcome.html" onsubmit="return validate()"> <label>NAME: </label> <input name="fname" type="text" class="form1"> <br/> <label>EMAIL: </label> <input name="femail" type="email" class="form2"> <br/> <label>PHONE: </label> <input name="fnumber" type="text" class="form3"> <center> <input type="submit" class="btn btn-danger" value="SAVE $150"> </input> </center> </form> </div> <div class="col-md-3"></div> </div> <div class="panel panel-primary"> <div class="panel-heading"><span class="glyphicon glyphicon-ok-circle"></span>Quality Work &nbsp; <span class="glyphicon glyphicon-ok-circle"></span> Professional Painters &nbsp; <span class="glyphicon glyphicon-ok-circle"></span> Flexible Schedules </div> </div> </div> </div> <!-- End of header --> <div class="row"> <div class="col-md-2"> </div> <div class="col-md-8"> <strong class="title">Professional Painters </strong> </br> <strong class="subtitle">Tackling Residential & Commerical Painting Projects</strong> </br> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida massa pharetra, tempor ligula ut,aliquet nulla. Quisque eu quam turpis. Sed portitor mauris nec quam dignissim, et placerat odio scelerisque. In hac habitussa platea dictumst. Proin et accumsan nunc, sit amet bibenndum parus. Proin at euismod ante. Phasellus ipsum orcii feugiat tristique mollis vitae, sagittis sollicitudin libero.In lompus <br/>ex non ipsum prctium, ae conseqaut justo fringilla. </p> </div> <div class="col-md-2"> </div> </div> <!--End of first part --> <br/> <div class="row"> <div class="col-md-2"> </div> <div class="col-md-8"> <strong class="subtitle">Why Clients Choose To Hire Our Team: </strong> </br> <p> <label class="content"> <img src="images\\listicon.png"> Mauris sit amet urna etleo pulvinar tristique </label> </p> <p> <label class="content"> <img src="images\\listicon.png"> Nameu eros mollis, interdum sapren tincidant accumsan erat. </label> </p> <p> <label class="content"> <img src="images\\listicon.png"> Maecenas rutrum libero ac drum volutpat, eu veucula risas molestre </label> </p> <p> <label class="content"> <img src="images\\listicon.png"> Mauris et tellus in lucas effucutar fringilla </label> </p> <p> <label class="content"> <img src="images\\listicon.png"> Naliam lacinia nulla eget quam ornaz blandit</label> </p> <p> <label class="content"> <img src="images\\listicon.png"> Sed mollis magna eu mi allquet scalerisque</label> </p> </div> <div class="col-md-2"> </div> </div> <!-- End of 2nd part--> <div class="row"> <div class="col-md-2"> </div> <div class="col-md-8"> <p> Donec allquem sit amet nisised consequent. Ttiam gravida nisi. Interdam et malesuada fames ac ante ipsum primia in faucibus. Aeneam feugiat lacinia velit non lacinia. Proin eget tristique leo. </p> </div> <div class="col-md-2"> </div> </div> <!-- end of 3rd part--> <!-- footer navbar--> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> </div> <ul class="nav navbar-nav"> <li> <label>SCHEDULE YOUR FREE ESTIMATE!</label> <label class="content1" style=" font-size: 25px; padding-left: 11px; padding-bottom: 0px; padding-top: 7px; margin-top: -19px;"> 555-123-4567</label> </li> </ul> </div> </nav> <hr class="last"> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> </body> </html>致电。第二个参数是以秒为单位的时间延迟。

Invoke()