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 …