forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   Общие вопросы (http://forum.boolean.name/forumdisplay.php?f=166)
-   -   Сглаживание перехода между сценами (http://forum.boolean.name/showthread.php?t=17804)

Lestar 28.01.2013 01:28

Сглаживание перехода между сценами
 
Часто возникает необходимость в сглаживании переходов между сценами. Незамысловатое, простое решение. Создаем плейник, скейлим его, выставляем ротейшен и позишет, чтобы он полностью перекрывал обзор камере, на него натягивает текстуру(белую/ черную/ другую).На плейник вешаем скрипт приведенный ниже. Сохраняем префаб.
Код:

using UnityEngine;
using System.Collections;

public class LevelChange : MonoBehaviour
{
    enum TransitDirection { Up, Down }
    TransitDirection transitDirection=TransitDirection.Up;
 
    private float alpha = 0f;
    private Color start_color;
    private MeshFilter mf;
    private Mesh mesh;
    private Color[] colors;
    public string LevelNumber;
    public float DeltaAlpha = 0.0005f;

    void Start()
    {
        DontDestroyOnLoad(transform);

        mf = gameObject.GetComponent<MeshFilter>();
        mesh = mf.mesh;

        start_color = new Color(0f, 0f, 0f, alpha);
        colors = new Color[mesh.vertexCount];

        for (int i = 0; i < colors.Length; i++)
        {
            colors[i] = start_color;
        }

        mesh.colors = colors;
        mf.mesh = mesh;
    }


    void Update()
    {
        if(transitDirection==TransitDirection.Down)
          {
            if (Application.isLoadingLevel) return;
          }

        for (int i = 0; i < colors.Length; i++)
        {
            if (transitDirection == TransitDirection.Up) alpha += DeltaAlpha;
            else alpha -= DeltaAlpha;

            colors[i] = start_color;
            colors[i].a = alpha;
        }

        mesh.colors = colors;
        mf.mesh = mesh;

        if (transitDirection==TransitDirection.Up)
        {
            if (alpha >= 1)
            {
                Application.LoadLevel(LevelNumber);
                transitDirection = TransitDirection.Down;
            }
        }
        else if (alpha <= 0.0001f) Destroy(gameObject);
    }
}

В событие, вызывающее переход между уровнями передаем инстанс нашего плейника и левел, который грузим.
Код:

transitPlane=(GameObject)Instantiale(TransitPlane);
transitPlane.GetComponent<LevelChange>().LevelNumber = "Scene2";


mepihin 29.01.2013 22:51

Ответ: Сглаживание перехода между сценами
 
Попробовал твою систему, сделал как все ты говорил, создал плейн, текстуру на него и скрипт, сохранил его префаб и удалил со сцены, в свой скрипт Health вставляю:
PHP код:

using UnityEngine;
using System.Collections;

public class 
Health MonoBehaviour {
    
    public 
int health 80;
    private 
int maxHealth 80;
    
    
void OnGUI()
    {
        
GUI.Box(new Rect(10,Screen.height-55,150,20),"");
        
GUI.Label(new Rect(25,Screen.height-55,150,20),"Health: " maxHealth " / " health);
        
        if(
health >= maxHealthhealth maxHealth;
        if(
health <= 0)
        {
            
health 0;
            
transitPlane=(GameObject)Instantiate(TransitPlane);
            
transitPlane.GetComponent<LevelChange>().LevelNumber "Scene2";
    
    } 

Пишет ошибки:
Цитата:

The name `TransitPlane' does not exist in the current context
The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object )' has some invalid arguments
The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object )' has some invalid arguments

The name `transitPlane' does not exist in the current context

The name `transitPlane' does not exist in the current context

Lestar 29.01.2013 22:55

Ответ: Сглаживание перехода между сценами
 
Обьяви transitPlane,TransitPlane перед тем, как использовать. В паблик поле TransitPlane в инспекторе засунь свой префаб.

mepihin 29.01.2013 23:54

Ответ: Сглаживание перехода между сценами
 
точно...


Часовой пояс GMT +4, время: 10:33.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot