涓嶅叆闂ㄧ殑纰版挒

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>

  1. 瀹炵幇鑴氭湰鎸傝浇鐗╀綋鍓嶅悗绉诲姩 宸﹀彸鏃嬭浆 鍒氫綋缁勪欢锛?/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>
    }

     

  2. 鍦≒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;
        // 灏忕悆鐨勮鏃跺櫒娓呴浂
    }

     

  3. 纰版挒娑堥櫎鍙婂姞鍒嗛€昏緫

    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);
        }

     

  4. 鍒嗘暟鍙婃椂闂寸殑鏄剧ず

    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>

以上是关于涓嶅叆闂ㄧ殑纰版挒的主要内容,如果未能解决你的问题,请参考以下文章

鎴戜笌涓栫晫鏍兼牸涓嶅叆,鎴戜笌python鎯烘兒鐩告儨

鍒濆叆闂ㄦ椂瑙佸埌鐨勪竴浜涙瘮杈冩湁鐢ㄧ殑鍑芥暟

銆孷UE 瀛﹂櫌銆嶅埄鐢ㄥ壀杈戔€滅灛闂磋浆绉烩€濓紝浜轰汉閮芥槸榄旀湳甯堬紒

Git 宸ヤ綔娴佺▼锛汫raphQL 浠庡叆闂ㄥ埌瀹炶返锛汚ngular 9.0 鍙戝竷锛両vy 姝e紡鎶佃揪

浣犲彲鑳戒笉鐭ラ亾鐨?5涓湁鐢ㄧ殑Github鍔熻兘