Skip to content

Instantly share code, notes, and snippets.

@anzfactory
Last active November 9, 2015 16:53
Show Gist options
  • Save anzfactory/d0deec6e7dc593851dec to your computer and use it in GitHub Desktop.
Save anzfactory/d0deec6e7dc593851dec to your computer and use it in GitHub Desktop.
iTweenでuGUIの色をかえる
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