1. 程式人生 > >識別Vuforia識別碼,使得和識別碼繫結的面顏色閃爍

識別Vuforia識別碼,使得和識別碼繫結的面顏色閃爍

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeClour : MonoBehaviour
{
    public GameObject obj;//和識別碼繫結的面
    private float shake;//建立一個常量,用來接收時間的變化值
   // Use this for initialization
    void Start ()
    {
		
	}
	
	// Update is called once per frame
	void Update ()
    {
        shake += Time.deltaTime;
        if (shake % 1 > 0.5f)
        {
       if (obj.GetComponent<MeshRenderer>().enabled==true)//當相機識別識別碼時會啟用MeshRenderer元件,通過此元件有無控制閃爍的開始
            {
            obj.GetComponent<MeshRenderer>().material.color = Color.blue;
        }
        }
        else if (obj.GetComponent<MeshRenderer>().enabled == true)
        {
            obj.GetComponent<MeshRenderer>().material.color = Color.red;
        }

    }
}