涓嶅叆闂ㄧ殑纰版挒
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了涓嶅叆闂ㄧ殑纰版挒相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e7%a2%b0%e6%92%9e' title='纰版挒'>纰版挒
ace 鎷栨嫿 div one NPU upd collision ack纰版挒缁冧範
鐗╀綋纰版挒涓嶅悓棰滆壊灏忕悆瀹炵幇鍒嗘暟鐨勫姞鍑?/p>
鍒嗕负4閮ㄥ垎
-
鐗╀綋鐨勭Щ鍔?/span>
-
鐞冪殑闅忔満鐢熸垚
-
纰版挒鍚庣悆娑堝け锛堝垎鏁扮殑鍔犲噺锛?/span>
-
鍒嗘暟鐨勬樉绀猴紙鍒嗘暟鐨勫姞鍑忥級
涓嬮潰涓哄叿浣撲唬鐮?/span>
-
瀹炵幇鑴氭湰鎸傝浇鐗╀綋鍓嶅悗绉诲姩 宸﹀彸鏃嬭浆 鍒氫綋缁勪欢锛?/span>
this.gameObject.AddComponent<Rigidbody>(); // 鍏堝湪 Start 涓拷鍔犲垰浣撶粍浠?/span>// 鍙互鐩存帴鍦ㄧ墿浣撲笂add this.transform.Translate(new Vector3(0,0,Input.GetAxis("Vertical"))*0.1f); // 鍓嶅悗绉诲姩 this.transform.Rotate(0,Input.GetAxis("Horizontal"),0); // 宸﹀彸杞悜 if (Input.GetKey(KeyCode.Space)) { this.transform.Translate(Vector3.up*0.3f); // 妫€娴嬫槸鍚︽寜涓嬬┖鏍奸敭 鐒跺悗璺?/span> }
-
鍦≒lane涓婇殢鏈轰綅缃紝闅忔満棰滆壊鐢熸垚灏忕悆锛?/span>
Color[] color= new Color[]{Color.red,Color.blue,Color.black}; // 棰滆壊鏁扮粍 private float SphereTimer = 0; // 鍏堝湪 Update 澶栭儴鍒涘缓璁℃椂鍣?/span> --------------------------------------------- SphereTimer += Time.deltaTime; // 鏃堕棿澧為暱 // print(SphereTimer); if (SphereTimer > 3) { GameObject Spheretemp = GameObject.CreatePrimitive(PrimitiveType.Sphere); // 鍒涘缓灏忕悆 Spheretemp.transform.position = new Vector3(Random.Range(-4.5f, 4.5f) , 0.5f, Random.Range(-4.5f, 4.5f)); // 闅忔満浣嶇疆 Spheretemp.GetComponent<MeshRenderer>().material.color = color[Random.Range(0, 3)]; // 闅忔満棰滆壊 Destroy(Spheretemp, 6); // 寤惰繜閿€姣?/span> SphereTimer = 0; // 灏忕悆鐨勮鏃跺櫒娓呴浂 }
-
纰版挒娑堥櫎鍙婂姞鍒嗛€昏緫
public int Score; // 鍏紑鍒嗘暟 鏂逛究鍦ㄦ樉绀虹被涓幏鍙?/span> -------------------------------------------------- private void OnCollisionEnter(Collision collision)// 纰版挒妫€娴? { // 纰板埌涓嶅悓棰滆壊鐨勭悆 缁欏姞鍒嗘柟娉曚紶鍏ヤ笉鍚岀殑鍙傛暟 if (collision.gameObject.GetComponent<MeshRenderer>(). material.color == Color.red) { AddScore(1); } if (collision.gameObject.GetComponent<MeshRenderer>(). material.color == Color.blue) { AddScore(2); } if (collision.gameObject.GetComponent<MeshRenderer>(). material.color == Color.black) { AddScore(3); } // 濡傛灉妫€娴嬪埌纰版挒鐗╀綋鐨勫悕瀛椾负鐞? 鍒欓攢姣佽繖涓墿浣?/span> if (collision.gameObject.name == "Sphere") { Destroy(collision.gameObject); } } // 杩欐槸涓€涓姞鍒嗘柟娉? 鍙互鍐嶆湰绫讳腑鍐? 涔熷彲浠ュ湪鍒殑绫讳腑鍐?/span> private void AddScore(int score) { Score += score; // print(Score); }
-
鍒嗘暟鍙婃椂闂寸殑鏄剧ず
public Text Scores; public Text Timer; float time = 0; // 鍏紑澹版槑Text 鏂逛究鎷栨嫿锛屽湪澶栭儴澹版槑璁℃椂鍣?/span> -------------------------------------------------- int Score = TankCollder.Score; // 鑾峰彇TankCollder涓殑鍒嗘暟 Scores.text = string.Format("{0:d2}", Score); // 鏄剧ず 鍒嗘暟 time+= Time.deltaTime; // 璁℃椂 Timer.text = string.Format("{0:d2}",(int)time); // 鏄剧ず鏃堕棿 锛屾椂闂翠竴瀹氳寮鸿浆鎴愭暣鏁板摝~
Unity鐨勫満鏅拰鎷栨嫿灏变笉鎴浘浜?/span>
以上是关于涓嶅叆闂ㄧ殑纰版挒的主要内容,如果未能解决你的问题,请参考以下文章
銆孷UE 瀛﹂櫌銆嶅埄鐢ㄥ壀杈戔€滅灛闂磋浆绉烩€濓紝浜轰汉閮芥槸榄旀湳甯堬紒