usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassBling:MonoBehaviour{publicTexture img;publicfloat speed;publicstaticbool changeWhite =false;privatefloat alpha=0f;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}privatevoidOnGUI(){if(changeWhite){alpha += speed * Time.deltaTime;if(alpha>=1){changeWhite =false;}}else{if(alpha>0){alpha -= speed * Time.deltaTime;}}GUI.color =newColor(GUI.color.r, GUI.color.g, GUI.color.b, alpha);GUI.DrawTexture(newRect(0,0,Screen.width,Screen.height),img);}publicstaticvoidblinking(){changeWhite =true;}}
二、在角色腳本觸發物體腳本中引用閃爍腳本
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassFly:MonoBehaviour{//獲取小鳥(剛體)privateRigidbody2D bird;//速度publicfloat speed;//跳躍publicfloat jump;//是否存活publicstaticbool life =true;//獲取動畫器privateAnimator animator;// Start is called before the first frame updatevoidStart(){bird =GetComponent<Rigidbody2D>();animator =GetComponent<Animator>();}// Update is called once per framevoidUpdate(){//村換的時候才能運動if(life){ bird.velocity =newVector2(speed, bird.velocity.y);//鼠標點擊給目標一個縱向速度if(Input.GetMouseButtonDown(0)){bird.velocity =newVector2(bird.velocity.x, jump);}}}//如果碰撞器撞到了某個物體privatevoidOnCollisionEnter2D(Collision2D collision){if(life==true){Bling.blinking();}life =false;animator.SetBool("life",false);}}
// 變量
var a, b, c 8, 2.3, "hello"
var d float64;
e : 6var A []int;
var B [10]int;
C : [10]int{1, 2, 3, 4}
for i : 0; i < len(B); i {}
for _, value : range C {}
D make([]int, 3)
// len 4, cap 10, 擴容方式 cap*2
E : make([]int, 4, 10)
E …