Среда, 29 Мая 2024, 08:25

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Resources.Load
Andruha93Дата: Пятница, 19 Июля 2013, 17:53 | Сообщение # 1
частый гость
Сейчас нет на сайте
Привет всем ! Постораюсь объяснить как можно кратче.
У меня есть 3 объекта, для каждого объекта есть по 4 текстуры.
При нажатии на определеные NGUI кнопки в переменную objMat; добавляется какой то один из трех объектов и в зависимости от того какое имя у этого объекта открывается доступ к его 4-м текстурам и потом я выбираю понравившуюся текстуру, сами текстуры динамически загружаются из папки Resources.
Поидее после запуска игры все переменные в этом скрипте должны быть пустыми, но на деле получается что всем переменным с текстурами сразу же присвоены текстуры ПОСЛЕДНЕГО объекта в скрипте (в моем случае это culinder1)

Код

  using UnityEngine;  
  using System.Collections;  

  public class ChangeMaterial : MonoBehaviour {  
           public Texture2D _texture01;  
           public Texture2D _texture02;  
           public Texture2D _texture03;  
           public Texture2D _texture04;  
           public GameObject objMat;  // Сюда заносится объект который включен в данный момент, заносится он из скрипта CreateObject.  

             
           void Update()  
           {  
                   objMat = gameObject.GetComponent<CreateObjects>().ONobj;  
    if (!objMat)  
    {  
                    this._texture01 = null;  
         this._texture02 = null;  
                    this._texture03 = null;  
         this._texture04 = null;  
    }  
                     if (objMat == GameObject.Find ("sphere1"))  
                   {  
                      
                           string _texturePath01 = "Material&Texture/01/sphere01mat1";  
                           string _texturePath02 = "Material&Texture/01/sphere01mat2";  
                           string _texturePath03 = "Material&Texture/01/sphere01mat3";  
                           string _texturePath04 = "Material&Texture/01/sphere01mat4";  
                     _texture01 = (Texture2D)Resources.Load(_texturePath01, typeof(Texture2D));  
                     _texture02 = (Texture2D)Resources.Load(_texturePath02, typeof(Texture2D));  
                     _texture03 = (Texture2D)Resources.Load(_texturePath03, typeof(Texture2D));  
                     _texture04 = (Texture2D)Resources.Load(_texturePath04, typeof(Texture2D));  

                   }  

                   if (objMat == GameObject.Find ("box1"))  
                   {  
                           string _texturePath01 = "Material&Texture/02/box02mat1";  
                           string _texturePath02 = "Material&Texture/02/box02mat2";  
                           string _texturePath03 = "Material&Texture/02/box02mat3";  
                           string _texturePath04 = "Material&Texture/02/box02mat4";  
                     _texture01 = (Texture2D)Resources.Load(_texturePath01, typeof(Texture2D));  
                     _texture02 = (Texture2D)Resources.Load(_texturePath02, typeof(Texture2D));  
                     _texture03 = (Texture2D)Resources.Load(_texturePath03, typeof(Texture2D));  
                     _texture04 = (Texture2D)Resources.Load(_texturePath04, typeof(Texture2D));  

                   }  

                   if (objMat == GameObject.Find ("culinder1"))  
                   {  
                           string _texturePath01 = "Material&Texture/03/culinder03mat1";  
                           string _texturePath02 = "Material&Texture/03/culinder03mat2";  
                           string _texturePath03 = "Material&Texture/03/culinder03mat3";  
                           string _texturePath04 = "Material&Texture/03/culinder03mat4";  
                     _texture01 = (Texture2D)Resources.Load(_texturePath01, typeof(Texture2D));  
                     _texture02 = (Texture2D)Resources.Load(_texturePath02, typeof(Texture2D));  
                     _texture03 = (Texture2D)Resources.Load(_texturePath03, typeof(Texture2D));  
                     _texture04 = (Texture2D)Resources.Load(_texturePath04, typeof(Texture2D));  

                   }
        }
}
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг