Last active
November 9, 2015 16:53
-
-
Save anzfactory/d0deec6e7dc593851dec to your computer and use it in GitHub Desktop.
iTweenでuGUIの色をかえる
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
using UnityEngine; | |
using UnityEngine.UI; | |
public class ChangeColor : MonoBehaviour | |
{ | |
private Image target; | |
private Color originalColor; | |
void Awake() | |
{ | |
this.target = this.gameObject.GetComponent<Image>(); | |
} | |
public void OnChangeColor(Button sender) | |
{ | |
this.originalColor = this.target.color; | |
iTween.ValueTo( | |
this.gameObject, | |
iTween.Hash( | |
"time", 2f, | |
"from", 0f, | |
"to", 1f, | |
"onupdate", "ChangeColorToYellow", | |
"oncomplete", "OnComplete", | |
"oncompleteparams", sender | |
) | |
); | |
} | |
public void ChangeColorToYellow(float newValue) | |
{ | |
var diff = Color.yellow - this.originalColor; | |
this.target.color = new Color( | |
this.originalColor.r + diff.r * newValue, | |
this.originalColor.g + diff.g * newValue, | |
this.originalColor.b + diff.b * newValue | |
); | |
} | |
public void OnComplete(Button sender) | |
{ | |
sender.gameObject.GetComponentInChildren<Text>().text = "Fin..."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment