2016年12月15日 星期四

12/16 紅綠燈


using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

// Use this for initialization
void Start () {
}
int c = 0;
// Update is called once per frame
void Update () {

c =c+1;

Image img1 = GameObject.Find ("Image").GetComponent<Image> ();
Image img2 = GameObject.Find ("Image1").GetComponent<Image> ();
Image img3 = GameObject.Find ("Image2").GetComponent<Image> ();

if (c % 15 >= 0 && c%15<=4)
{
img1.color = new Color(1.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
img2.color = new Color(0.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
img3.color = new Color(0.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
}
if (c % 15 >= 5 && c%15<=9)
{
img1.color = new Color(0.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
img2.color = new Color(1.0F, 1.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
img3.color = new Color(0.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
}
if (c % 15 >= 10 && c%15<=14)
{
img1.color = new Color(0.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
img2.color = new Color(0.0F, 0.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
img3.color = new Color(0.0F, 1.0F, 0.0F, 1.0F); // (紅red,綠green,藍blue,透明)
}

}
}

2016年12月1日 星期四

12/2 繞一圈



using UnityEngine;
using System.Collections;

public class NewBehaviourScript1 : MonoBehaviour
{

Vector3[] T = new Vector3[4];
// Use this for initialization
void Start()
{
T[0] = new Vector3(12f, 0, 12f);
T[1] = new Vector3(-12f, 0, 12f);
T[2] = new Vector3(-12f, 0, -8f);
T[3] = new Vector3(12f, 0, -8f);

}
int aa = 0;

// Update is called once per frame
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, T[aa], 10 * Time.deltaTime);
if (transform.position == T[aa])
aa = (aa + 1) % 4;
if(Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up* 20*Time.deltaTime);

}
}