using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextureTest : MonoBehaviour
{
Color setColor = new Color(1.0f, 0f, 0f);
Shader shader;
Material material;
Vector2 textureSize;
Vector2 textureOffset;
public int number = 0;
void Start()
{
Texture tex;
shader = this.GetComponent<Image>().material.shader;
material = new Material(shader);
tex =this.GetComponent<Image>().sprite.texture;
textureSize =new Vector2( tex.width, tex.height);
//全体サイズが1なので1つあたりの幅で割り、100を掛ける
textureOffset = new Vector2( 1 / textureSize.x * 100.0f, 1 / textureSize.y * 100.0f);
material.mainTextureOffset = new Vector2( textureOffset.x * number, 0f);
material.color = setColor;
this.GetComponent<Image>().material = material;
}
// Update is called once per frame
void Update()
{
}
void FixUpdate(){
}
private void OnDestroy()
{
if( material != null ){
Destroy(material);
material = null;
}
}
}