Created
July 13, 2018 08:33
-
-
Save todorok1/c5dd0940c35d8a409a0cd0d24246afc7 to your computer and use it in GitHub Desktop.
クリックしたらオブジェクトの色を変えよう
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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