美文网首页
Unity GameObject.CompareTag 用法

Unity GameObject.CompareTag 用法

作者: 醉杀楚天白 | 来源:发表于2017-12-31 11:18 被阅读0次

使用GameObject.CompareTag代替GameObject.tag:GameObject.tag会在内部循环调用对象分配的标签属性并分配额外的内存。

    // When this game object intersects a collider with 'is trigger' checked, 
    // store a reference to that collider in a variable named 'other'..
    void OnTriggerEnter(Collider other) 
    {
        // ..and if the game object we intersect has the tag 'Pick Up' assigned to it..
        if (other.gameObject.CompareTag ("Pick Up"))
        {
            // Make the other game object (the pick up) inactive, to make it disappear
            other.gameObject.SetActive (false);

            // Add one to the score variable 'count'
            count = count + 1;

            // Run the 'SetCountText()' function (see below)
            SetCountText ();
        }
    }

相关文章

网友评论

      本文标题:Unity GameObject.CompareTag 用法

      本文链接:https://www.haomeiwen.com/subject/nmbogxtx.html