Skip to content

Instantly share code, notes, and snippets.

@komo91
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komo91/c7cd1c285388ec5c7a07 to your computer and use it in GitHub Desktop.
Save komo91/c7cd1c285388ec5c7a07 to your computer and use it in GitHub Desktop.
using UnityEngine;//使うライブラリの宣言
using System.Collections;
//MonoBehaviourを継承したPaintItクラスの宣言
public class PaintIt : MonoBehaviour {
private bool isPainted = false;//真偽値
private float timeFromPaint = 0.0f;//触れた時間を値として入れる
public float resetTime = 1.0f;
public Color color;
int count = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// 一度色づけられるとresetTime 間は保持されて、その後色が戻る
if ( isPainted )
{
timeFromPaint += Time.deltaTime; //deltaTimeは経過時間を表す
if ( timeFromPaint > resetTime )
{
//ここで指定された色に変える
GetComponent<Renderer>().material.color = new Color( 1.0f, 1.0f, 1.0f );
isPainted = false;
}
}
}
public void setColor()
{
// 色はインスペクタ上から指定可能
GetComponent<Renderer> ().material.color = color;
timeFromPaint = 0.0f;
isPainted = true;//trueのとき色が変わる
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment