Переехали на новый сайт!



Главная » Файлы » Unity3D » Скрипты

Изображение
Палитра
10 Мая 2014, 16:43
Код
using UnityEngine;
using System.Collections;

public class ChangeColor : MonoBehaviour
{
  public Texture2D colorTexture;
  public Renderer ColoredObject;
  private Rect textureRect = new Rect (10, 10, 200, 200);
   
  void OnGUI ()
  {
  GUI.DrawTexture (textureRect, colorTexture);
   
  if (Event.current.type == EventType.MouseUp) {
  Vector2 mousePosition = Event.current.mousePosition;
   
  if (mousePosition.x > textureRect.xMax || mousePosition.x < textureRect.x || mousePosition.y > textureRect.yMax || mousePosition.y < textureRect.y) {
  return;
  }
  float textureUPosition = (mousePosition.x - textureRect.x) / textureRect.width;
  float textureVPosition = 1.0f - ((mousePosition.y - textureRect.y) / textureRect.height);
   
  Color textureColor = colorTexture.GetPixelBilinear (textureUPosition, textureVPosition);
  //ColoredObject.Material.color = textureColor; // If enable this , Commenting on the next line.
  ColoredObject.sharedMaterial.color = textureColor;
  }
  }
}
  
Категория: Скрипты | Добавил: Unit
Просмотров: 678 | Загрузок: 65 | Комментарии: 2 | Рейтинг: 5.0/1
Всего комментариев: 2
Влад) пишет: | 22 Июля 2015 | 01:28 #1 Страница с комментарием Спам
Влад) Ссылка не работает!!!
Like | 0
Влад) пишет: | 22 Июля 2015 | 13:34 #2 Страница с комментарием Спам
Влад) Спасибо! Хотел повысить тебе репутацию за быстрою реакцию на коммент, но мне пишет что я смогу изменить репутацию через 7 дней)) не знаю почему так, но все ровно спасибо!
Like | 0
avatar