Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
クリックしたらオブジェクトの色を変えよう
Material mat;
void Start(){
mat = gameObject.GetComponent<MeshRenderer>().material;
}
public void OnPointerClick(PointerEventData pointerData){
Debug.Log(gameObject.name + " がクリックされた!");
Color initColor = new Color(1.0f, 1.0f, 0.5f);
Color targetColor = new Color(0.5f, 1.0f, 0.5f);
StartCoroutine(ClickAnim(initColor, targetColor, 1.0f));
}
IEnumerator ClickAnim(Color initColor, Color targetColor, float processTime){
float finishTime = Time.time + processTime;
while (true){
float diff = finishTime - Time.time;
if (diff <= 0){
break;
}
float rate = 1 - Mathf.Clamp01(diff / processTime);
mat.color = Color.Lerp(initColor, targetColor, rate);
yield return null;
}
mat.color = targetColor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.