Помогите изменить скрипт - Форум Игроделов
Сб, 04 Май 2024, 12:36 
 
Приветствую Вас Гость Главная | Регистрация | Вход
Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум Игроделов » UNITY3D » ОБЩИЕ ВОПРОСЫ » Помогите изменить скрипт
Помогите изменить скрипт
WolfДата: Вт, 01 Окт 2013, 05:59 | Сообщение # 1
 
Сообщений: 4
Награды: 0
Репутация: 0
Статус: Offline
Всем доброго времени я только начинаю изучать C# Помогите пожалуйста изменить скрипт загрузки сцены
Вообщем мне надо чтобы он работал без нажатиия кнопки Space т.е чтоб сцена со скриптом открылась и сразу началась загрузка следующей сцены

Вот сам скрипт:

Код
using UnityEngine;
using System.Collections;

public class AsyncLoadProgress : MonoBehaviour {

         private AsyncOperation async = null;
         private bool isLoading = false;
         public string levelName = "";
     public Texture backgroundBar;
    public Texture lineBar;
    public Texture GUITextureBackground;

         private IEnumerator _Start(){
                 Debug.Log( "Loading... " );
                 async = Application.LoadLevelAsync( levelName );
                 while( !async.isDone ){
                         Debug.Log( string.Format( "Loading {0}%", async.progress*100 ) );
                         yield return null;
                 }
                 Debug.Log( "Loading complete" );
                 isLoading = false;
                 yield return async;
         }

         private void OnGUI(){
       if(GUITextureBackground != null)
             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), GUITextureBackground);
                 if( !isLoading ){
          GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3), 512, 30),"Press space to Continue");
                         if(Input.GetKeyDown(KeyCode.Space)){
                    isLoading = true;
                    StartCoroutine("_Start");
                         }
                 } else{
          GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3)-20, 512, 30),"Loading...");
                         GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), 512, 10 ), backgroundBar, ScaleMode.StretchToFill, true, 1F);
          GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), async.progress*512, 10 ), lineBar, ScaleMode.StretchToFill, true, 1F);
                 }
         }
}
  


Заранее благодарен


Только начал изучать unity3d
 
СообщениеВсем доброго времени я только начинаю изучать C# Помогите пожалуйста изменить скрипт загрузки сцены
Вообщем мне надо чтобы он работал без нажатиия кнопки Space т.е чтоб сцена со скриптом открылась и сразу началась загрузка следующей сцены

Вот сам скрипт:

Код
using UnityEngine;
using System.Collections;

public class AsyncLoadProgress : MonoBehaviour {

         private AsyncOperation async = null;
         private bool isLoading = false;
         public string levelName = "";
     public Texture backgroundBar;
    public Texture lineBar;
    public Texture GUITextureBackground;

         private IEnumerator _Start(){
                 Debug.Log( "Loading... " );
                 async = Application.LoadLevelAsync( levelName );
                 while( !async.isDone ){
                         Debug.Log( string.Format( "Loading {0}%", async.progress*100 ) );
                         yield return null;
                 }
                 Debug.Log( "Loading complete" );
                 isLoading = false;
                 yield return async;
         }

         private void OnGUI(){
       if(GUITextureBackground != null)
             GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), GUITextureBackground);
                 if( !isLoading ){
          GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3), 512, 30),"Press space to Continue");
                         if(Input.GetKeyDown(KeyCode.Space)){
                    isLoading = true;
                    StartCoroutine("_Start");
                         }
                 } else{
          GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3)-20, 512, 30),"Loading...");
                         GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), 512, 10 ), backgroundBar, ScaleMode.StretchToFill, true, 1F);
          GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), async.progress*512, 10 ), lineBar, ScaleMode.StretchToFill, true, 1F);
                 }
         }
}
  


Заранее благодарен

Автор - Wolf
Дата добавления - 01 Окт 2013 в 05:59
HunjethДата: Вт, 01 Окт 2013, 13:54 | Сообщение # 2
 
Сообщений: 354
Награды: 1
Репутация: 112
Статус: Offline
Код
private IEnumerator _Start(){

поменять на
Код
void Start() {
isLoading = true;


Сообщение отредактировал Hunjeth - Вт, 01 Окт 2013, 13:54
 
Сообщение
Код
private IEnumerator _Start(){

поменять на
Код
void Start() {
isLoading = true;

Автор - Hunjeth
Дата добавления - 01 Окт 2013 в 13:54
игнатДата: Вт, 01 Окт 2013, 14:22 | Сообщение # 3
 
Сообщений: 706
Награды: 0
Репутация: 107
Статус: Offline
Hunjeth, причём тут это? Ведь написано:
Код
if( !isLoading ){  
           GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3), 512, 30),"Press space to Continue");  
                          if(Input.GetKeyDown(KeyCode.Space)){  
                     isLoading = true;  
                     StartCoroutine("_Start");  
                          }

Значит урезать:

Код
using UnityEngine;  
  using System.Collections;  

  public class AsyncLoadProgress : MonoBehaviour {  

          private AsyncOperation async = null;  
          public string levelName = "";  
      public Texture backgroundBar;  
     public Texture lineBar;  
     public Texture GUITextureBackground;  

void Start () {
StartCoroutine("_Start");
}  

         private IEnumerator _Start(){                    //Не помню, будет ли в void Start работать, поэтому сохранил.
                  Debug.Log( "Loading... " );  
                  async = Application.LoadLevelAsync( levelName );  
                  while( !async.isDone ){  
                          Debug.Log( string.Format( "Loading {0}%", async.progress*100 ) );  
                          yield return null;  
                  }  
                  Debug.Log( "Loading complete" );  
                  isLoading = false;  
                  yield return async;  
          }  

          private void OnGUI(){  
        if(GUITextureBackground != null)  
              GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), GUITextureBackground);  
           GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3)-20, 512, 30),"Loading...");  
                          GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), 512, 10 ), backgroundBar, ScaleMode.StretchToFill, true, 1F);  
           GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), async.progress*512, 10 ), lineBar, ScaleMode.StretchToFill, true, 1F);  
                  }  
          }  
  }  



Правила форума · участник GCC
 
СообщениеHunjeth, причём тут это? Ведь написано:
Код
if( !isLoading ){  
           GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3), 512, 30),"Press space to Continue");  
                          if(Input.GetKeyDown(KeyCode.Space)){  
                     isLoading = true;  
                     StartCoroutine("_Start");  
                          }

Значит урезать:

Код
using UnityEngine;  
  using System.Collections;  

  public class AsyncLoadProgress : MonoBehaviour {  

          private AsyncOperation async = null;  
          public string levelName = "";  
      public Texture backgroundBar;  
     public Texture lineBar;  
     public Texture GUITextureBackground;  

void Start () {
StartCoroutine("_Start");
}  

         private IEnumerator _Start(){                    //Не помню, будет ли в void Start работать, поэтому сохранил.
                  Debug.Log( "Loading... " );  
                  async = Application.LoadLevelAsync( levelName );  
                  while( !async.isDone ){  
                          Debug.Log( string.Format( "Loading {0}%", async.progress*100 ) );  
                          yield return null;  
                  }  
                  Debug.Log( "Loading complete" );  
                  isLoading = false;  
                  yield return async;  
          }  

          private void OnGUI(){  
        if(GUITextureBackground != null)  
              GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), GUITextureBackground);  
           GUI.Label(new Rect( (Screen.width / 2)-70, (Screen.height / 2) + (Screen.height / 3)-20, 512, 30),"Loading...");  
                          GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), 512, 10 ), backgroundBar, ScaleMode.StretchToFill, true, 1F);  
           GUI.DrawTexture( new Rect( (Screen.width / 2) -300, (Screen.height / 2) + (Screen.height / 3), async.progress*512, 10 ), lineBar, ScaleMode.StretchToFill, true, 1F);  
                  }  
          }  
  }  

Автор - игнат
Дата добавления - 01 Окт 2013 в 14:22
WolfДата: Чт, 03 Окт 2013, 14:36 | Сообщение # 4
 
Сообщений: 4
Награды: 0
Репутация: 0
Статус: Offline
Всем спасибо помогло

Только начал изучать unity3d
 
СообщениеВсем спасибо помогло

Автор - Wolf
Дата добавления - 03 Окт 2013 в 14:36
Форум Игроделов » UNITY3D » ОБЩИЕ ВОПРОСЫ » Помогите изменить скрипт
  • Страница 1 из 1
  • 1
Поиск:
Загрузка...

Game Creating CommUnity © 2009 - 2024