《UnityAPI.GameObject遊戲對象》(Yanlz+Unity+SteamVR+雲技術+5G+AI+VR雲遊戲+isStatic+SendMessage+Find+立鑽哥哥++OK++)

《UnityAPI.GameObject遊戲對象》

版本

作者

參與者

完成日期

備註

UnityAPI_GameObject_V01_1.0

嚴立鑽

 

2020.05.19

 

 

 

 

 

 

 

#《UnityAPI.GameObject遊戲對象》發佈說明:

++++“UnityAPI.GameObject遊戲對象是對UnityAPIGameObject類的剖析和拓展

立鑽哥哥:Unity是一個入門快、提高難的遊戲引擎,想要提升能力,至少需要越過3道坎:API+Shader+綜合能力

++1、API的積累:API的合理利用不僅可以減輕自己的編碼負擔,而且往往可以提高程序的運行效率;這也是鑽哥開始“Unity API”獨立打造分類的初衷

++2、Shader編程:想要做出一款精品遊戲往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系統,優化了繁雜的“Open GL”編程

++3、綜合能力(技術+業務+管理):一款產品的製作除了功能編程外,往往會涉及很多其他領域,例如產品架構、UI交互設計、模型製作等,作爲主要的編程人員,對其他相關領域的瞭解程序往往會影響到產品製作直至最後的產品體驗

++++立鑽哥哥一直在推動【VR雲遊戲=Unity+SteamVR+雲技術+5G+AI,這個只是一個引子,拋磚引玉讓大家對整個知識體系有一個明確的落地方向,寶寶們可以根據自己的興趣方向進行拓展:比如Unity這裏是指一種“3D遊戲引擎”,也可拓展至“UE4Cocos2dx”等遊戲引擎;SteamVR是一種跨硬件解決方案,也可拓展至“VRTK”等第三方插件;“雲技術+5G”是一種跨平臺解決方案的核心技術,同樣可拓展至其他平臺解決方案;AI也是一種先進技術的舉例,也可以拓展至任何一種前沿技術

 

 

@@提示:有些博客可能只是開了頭,如果感興趣的同學,可以“點贊”或“評論區留言”,只要關注的同學多了,那就會繼續完善喲!(“++==”,表示沒有寫完的,如果關注度不高就不完善了;“++ok++”,表示此篇博客已經完成,是階段性完整的!)

 

$$$$博客溯源:

++++VR雲遊戲=Unity+SteamVR+雲技術+5G+AI;(說明:AI人工智能不是我們的主要研究技術,只是瞭解一下,領略一下有風的感覺!但是,VR是我們的研究重點

++++【Unity API】分類:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

++++【Unity開發基礎】分類:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html

++++【Linux系統編程】分類:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html

++++【C++C鑄就生存利器】分類:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html

++++【人工智能AI2026】分類:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html

++++【立鑽哥哥CSDN空間】:https://blog.csdn.net/VRunSoftYanlz/

 

 

 

 

 

#GameObject遊戲對象

#GameObject遊戲對象

#GameObject遊戲對象

++A1、Description描述

++B2、Variables變量

++C3、Public Function共有函數

++D4、Message消息

 

 

#A1、Description描述

#A1、Description描述

++A1、Description描述

++++立鑽哥哥:GameObject(遊戲對象)是Unity場景裏面所有實體的基類

++++[Namespace]:UnityEngine Parent class: Object;

++++[Object對象]:Unity所有對象的基類

立鑽哥哥:Base class for all entities in Unity scenes;

 

 

 

 

 

 

#B2、Variables變量

#B2、Variables變量

++B2、Variables變量

++++B2.1、activeInHierarchy

++++B2.2、activeSelf

++++B2.3、isStatic

++++B2.4、layer

++++B2.5、scene

++++B2.6、tag

++++B2.7、transform

++++B2.8、YanlzXREngine.GameObject.Variables

 

 

++B2.1、activeInHierarchy

++B2.1、activeInHierarchy

++B2.1、activeInHierarchy

++++立鑽哥哥:在層級激活

bool activeInHierarchy;

++++場景中的激活對象是否激活?

++++如果GameObject.activeSelf屬性以及所有它的父級已啓動:可以知道一個遊戲物體在遊戲中是否是激活的

 

 

 

 

 

++B2.2、activeSelf

++B2.2、activeSelf

++B2.2、activeSelf

++++立鑽哥哥:激活自己

bool activeSelf;

++++該遊戲對象的局部激活狀態(只讀

++++返回該遊戲對象的局部激活狀態,設置是使用GameObject.SetActive;注意遊戲對象可以是不激活的,因爲父對象沒有激活,即使它返回True;這個狀態將被用在當所有父對象都是激活的;使用GameObject.activeInHierarchy來檢測遊戲對象在場景中實際是否是激活的

 

 

 

 

 

++B2.3、isStatic

++B2.3、isStatic

++B2.3、isStatic

++++立鑽哥哥:是否靜態

bool isStatic;

++++如果一個遊戲對象是靜態僅在編輯器API指定

++++如果任意對象設置爲靜態標識返回true

++++可參考:GameObjectUtility.SetStaticEditorFlags;

 

 

 

 

 

++B2.4、layer

++B2.4、layer

++B2.4、layer

++++立鑽哥哥:

int layer;

++++遊戲對象所在的層,層的範圍是在[0...31]之間

++++層可以用於攝像機的選擇性渲染或者忽略光線投射

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    void MyTestFunc(){

        gameObject.layer = 2;

    }

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++B2.5、scene

++B2.5、scene

++B2.5、scene

++++立鑽哥哥:場景

public SceneManagement.Scene scene;

++++場景物體(Scene that the GameObject is part of.)

 

 

 

 

 

++B2.6、tag

++B2.6、tag

++B2.6、tag

++++立鑽哥哥:標籤

string tag;

++++這個遊戲對象的標籤

++++標籤可以用於標識遊戲對象;標籤必須在使用之前在標籤管理器裏面先聲明

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    void MyTestFunc(){

        gameObject.tag = YanlzPlayer;

    }

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++B2.7、transform

++B2.7、transform

++B2.7、transform

++++立鑽哥哥:變換

Transform transform;

++++附加於這個遊戲對象上的變換(如果沒有則爲空)

using UnityEngine

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public GameObject other;

 

    void MyTestFunc(){

        other.transform.Translate(1, 1, 1);

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

 

 

#C3、Constructors構造器

#C3、Constructors構造器

++C3、Constructors構造器

++++C3.1、GameObject

++++C3.2、YanlzXREngine.GameObject.Constructors

 

 

++C3.1、GameObject

++C3.1、GameObject

++C3.1、GameObject

++++立鑽哥哥:遊戲對象

GameObject(string name);

GameObject();

GameObject(string name, params Type[] components);

++++創建一個新的遊戲物體,命名爲name

++++一個變換組件(Transform)總是被添加到遊戲對象

++++創建一個遊戲對象並且附加指定的組件

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public GameObject player;

 

    void MyTestFunc(){

        //player = new GameObject();

        player = new GameObject(YanlzPlayer);

 

        player.AddComponent(Rigidbody);

        player.AddComponent(BoxCollider);

    }    //立鑽哥哥:void MyTestFunc(){}

    

}    //立鑽哥哥:public class YanlzGameObject : MonoBehaviour{}

 

 

 

 

 

 

 

#D4、Functions函數

#D4、Functions函數

++D4、Functions函數

++++D4.1、AddComponent

++++D4.2、BroadcastMessage

++++D4.3、CompareTag

++++D4.4、GetComponent

++++D4.5、GetComponentInChildren

++++D4.6、GetComponentInParent

++++D4.7、GetComponents

++++D4.8、GetComponentsInChildren

++++D4.9、GetComponentsinParent

++++D4.10、SampleAnimation

++++D4.11、SendMessage

++++D4.12、SendMessageUpwards

++++D4.13、SetActive

++++D4.14、YanlzXREngine.GameObject.Functions

 

 

++D4.1、AddComponent

++D4.1、AddComponent

++D4.1、AddComponent

++++立鑽哥哥:添加組件

Component AddComponent(string className);

Component AddComponent(Type componentType);

T AddComponent();

++++添加一個名稱爲className的組件到遊戲對象

++++用這個函數改變運行中的物體的行爲;可以用傳遞腳本名稱的方法,把程序腳本加載給遊戲內物體

++++有些組件也需要同一個遊戲物體有其他組件;當然這個函數會自動添加那些需要的組件,比如當添加一個HingeJoint組件,這個函數會自動添加一個Rigidbody組件

++++給遊戲物體添加一個名稱爲componentType的組件類;C#用戶可以使用泛型版本

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public SphereCollider sc;

 

    void MyTestFunc(){

        //sc = gameObject.AddComponent<SphereCollider>();

        sc = gameObject.AddComponent(SphereCollider) as SphereCollider;

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.2、BroadcastMessage

++D4.2、BroadcastMessage

++D4.2、BroadcastMessage

++++立鑽哥哥:廣播消息

void BroadcastMessage(string methodName, object parameter=null, SendMessageOptions options=SendMessageOptions.RequireReceiver);

++++對此遊戲對象及其子對象的所有MonoBehaviour中調用名稱爲methodName的方法

++++接受消息的方法可以通過不要參數的方法來選擇忽略參數;當選項被設置爲SendMessageOptions.RequireReceiver時,如果消息沒有被任何一個組件處理,則會打印一個錯誤

using UnityEngine;

using System.Collections;

 

public class YanlzGameObject : MonoBehaviour{

 

    void MyApplyDamage(float damage){

        Debug.Log(damage);

    }    //立鑽哥哥:void MyApplyDamage(){}

 

    void MyTestFunc(){

        gameObject.BroadcastMessage(MyApplyDamage, 5.0F);

    }    //立鑽哥哥:void MyTestFunc(){}

    

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.3、CompareTag

++D4.3、CompareTag

++D4.3、CompareTag

++++立鑽哥哥:比較標籤

bool CompareTag(string tag);

++++[tag]:比較的標籤

++++此遊戲對象是否被標記爲tag標籤?

using UnityEngine;

using System.Collections;

 

public class YanlzGameObject : MonoBehaviour{

 

    void OnTriggerEnter(Collider other){

        if(other.gameObject.CompareTag(YanlzPlayer)){

            Destroy(other.gameObject);

        }

    }    //立鑽哥哥:void OnTriggerEnter(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.4、GetComponent

++D4.4、GetComponent

++D4.4、GetComponent

++++立鑽哥哥:獲取組件

Component GetComponent(Type type);

T GetComponent();

Component GetComponent(string type);

++++[type]:檢索組件的類型

++++如果這個遊戲對象附件了一個類型爲type的組件,則返回該組件,否則爲空

++++GetComponent是訪問別的組件的原始方法;通過這個函數可以訪問內置組件或腳本

++++由於性能原因,最好使用TypeGetComponent,而不是用字符串;不過有時可能無法得到Type,可以通過名字而不是Type來訪問組件

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public HingeJoint hinge;

 

    void MyTestFunc(){

        //hinge = gameObject.GetComponent(HingeJoint) as HingeJoint;

        hinge = gameObject.GetComponent<HingeJoint>();

 

        hinge.useSpring = false;

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.5、GetComponentInChildren

++D4.5、GetComponentInChildren

++D4.5、GetComponentInChildren

++++立鑽哥哥:獲取子對象組件

Component GetComponentInChildren(Type type);

T GetComponentInChildren();

++++[type]:檢索組件的類型

++++返回此遊戲對象或者它的所有子對象上(深度優先)的類型爲type的組件

++++只返回激活的組件

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public HingeJoint hinge;

 

    void MyTestFunc(){

        hinge = gameObject.GetComponentInChildren<HingeJoint>();

        hinge.useSpring = false;

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.6、GetComponentInParent

++D4.6、GetComponentInParent

++D4.6、GetComponentInParent

++++立鑽哥哥:獲取父對象組件

Component GetComponentInParent(Type type);

T GetComponentInParent();

++++[type]:查找組件的類型

++++從父對象查找組件

++++向上遞歸直到找到一個有效的組件,否則返回空

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public HingeJoint hinge;

 

    void MyTestFunc(){

        hinge = gameObject.GetComponentInParent<HingeJoint>();

        hinge.useSpring = false;

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.7、GetComponents

++D4.7、GetComponents

++D4.7、GetComponents

++++立鑽哥哥:獲取組件列表

Component[] GetComponents(Type type);

T[] GetComponents();

++++[type]:檢索組件的類型

++++返回該遊戲對象所有type類型的組件類表

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public HingeJoint[] hingeJoints;

 

    void MyTestFunc(){

        hingeJoints = gameObject.GetComponents<HingeJoint>();

        foreach(HingeJoint joint in hingeJoints){

            joint.useSpring = false;

        }

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.8、GetComponentsInChildren

++D4.8、GetComponentsInChildren

++D4.8、GetComponentsInChildren

++++立鑽哥哥:獲取子對象組件列表

Component[] GetComponentsInChildren(Type type, bool includeInactive=false);

T[] GetComponentsInChildren(bool includeInactive);

T[] GetComponentsInChildren();

++++[type]:檢索組件的類型

++++[includeInactive]:在查找集裏面應該包括非激活的組件嗎?

++++返回此遊戲對象與其子對象所有type類型的組件

++++搜索組件進行遞歸子對象,所以它包括子對象的子對象等

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public HingeJoint[] hingeJoints;

 

    void MyTestFunc(){

        hingeJoints = gameObject.GetComponentsInChildren<HingeJoint>();

        foreach(HingeJoint joint in hingeJoints){

            joint.useSpring = false;

        }

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.9、GetComponentsInParent

++D4.9、GetComponentsInParent

++D4.9、GetComponentsInParent

++++立鑽哥哥:獲取父對象組件列表

Component[] GetComponentsInParent(Type type, bool includeInactive=false);

T[] GetComponentsInParent(bool includeInactive);

T[] GetComponentsInParent();

++++[type]:檢索組件的類型

++++[includeInactive]:在查找集裏面應該包括非激活的組件嗎?

++++返回此遊戲對象與其父對象所有type類型的組件

++++搜索組件進行遞歸父對象,所以它包含父對象的父對象等

using UnityEngine;

using System.Collections;

 

public class YanlzGameObject : MonoBehaviour{

    public HingeJoint[] hingeJoints;

 

    void MyTestFunc(){

        hingeJoints = gameObject.GetComponentsInParent(typeof(HingeJoint));

        foreach(HingeJoint joint in hingeJoints){

            joint.useSpring = false;

        }

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.10、SampleAnimation

++D4.10、SampleAnimation

++D4.10、SampleAnimation

++++立鑽哥哥:採樣動畫

void SampleAnimation(AnimationClip animation, float time);

++++用於任何動畫剪輯在給定的時間採樣動畫

++++處於性能考量,推薦使用動畫界面;這個用於在給定的time來採樣animation;任何動畫的組件屬性的剪輯將被替換爲採樣的值;大多數可以使用Animation.Play替代;當需要在一個無序的幀或基於特定的輸入時,SampleAnimation最有用

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public AnimationClip clip;

 

    void Update(){

        gameObject.SampleAnimation(clip, clip.length - Time.time);

    }    //立鑽哥哥:void Update(){}

   

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

 

++D4.11、SendMessage

++D4.11、SendMessage

++D4.11、SendMessage

++++立鑽哥哥:發送消息

void SendMessage(string methodName, object value=null, SendMessageOptions options=SendMessageOptions.RequireReceiver);

++++[methodName]:調用的方法名

++++[value]:可選參數,被調用的方法傳遞的值

++++[options]:如果目標對象方法不存在,應該引發錯誤嗎?

++++在此遊戲對象所有MonoBehaviour上調用名稱爲methodName的方法

++++接收消息的方法可以通過不要參數的方法來選擇忽略參數;當選項被設置爲SendMessageOptions.RequireReceiver時,如果消息沒有被任何一個組件處理,則會打印一個錯誤

++++注意:消息不會發送到非激活的對象上(如:哪些在編輯器或者通過SetActive已經關閉的對象)

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    

    void MyApplyDamage(float damage){

        Debug.Log(damage);

    }    //立鑽哥哥:void MyApplyDamage(){}

 

    void MyTestFunc(){

        gameObject.SendMessage(MyApplyDamage, 5.0F);

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.12、SendMessageUpwards

++D4.12、SendMessageUpwards

++D4.12、SendMessageUpwards

++++立鑽哥哥:向上發送消息

void SendMessageUpwards(string methodName, object value=null, SendMessageOptions options=SendMessageOptions.RequireReceiver);

++++[methodName]:調用的方法名

++++[value]:可選參數,被調用的方法傳遞的值

++++[options]:如果目標對象方法不存在,應該引發錯誤嗎?

++++調用此遊戲對象及其behaviour的父對象上所有MonoBehaviour名爲methodName的方法

++++接收消息的方法可以通過不要參數的方法來選擇忽略參數,當選項被設置爲SendMessageOptions.RequireReceiver時,如果消息沒有被任何一個組件處理,則會打印一個錯誤

++++注意:消息不會發送到非激活的對象上(如:那些在編輯器或者通過SetActive已經關閉的對象)

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

 

    void MyApplyDamage(float damage){

        Debug.Log(damage);

    }    //立鑽哥哥:void MyApplyDamage(){}

 

    void MyTestFunc(){

        gameObject.SendMessageUpwards(MyApplyDamage, 5.0F);

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D4.13、SetActive

++D4.13、SetActive

++D4.13、SetActive

++++立鑽哥哥:設置激活

void SetActive(bool value);

++++激活/停用此遊戲對象

++++注意:一個遊戲對象可以是非活動狀態,因爲它的父對象不是激活的,這種情況下,調用SetActive()仍不能激活它,但僅能設置此遊戲對象的局部狀態,可以使用GameObject.activeSelf來檢查;此狀態用於當所有父對象都是激活狀態

 

 

 

 

 

 

 

#E5、Static Functions靜態函數

#E5、Static Functions靜態函數

++E5、Static Functions靜態函數

++++D5.1、CreatePrimitive

++++D5.2、Find

++++D5.3、FindGameObjectsWithTag

++++D5.4、FindWithTag

++++D5.5、YanlzXREngine.GameObject.StaticFunctions

 

 

++D5.1、CreatePrimitive

++D5.1、CreatePrimitive

++D5.1、CreatePrimitive

++++立鑽哥哥:創建原型對象

static GameObject CreatePrimitive(PrimitiveType type);

++++[type]:要創建的原型對象的類型

++++創建一個帶有原型網絡渲染器和適當的碰撞器的遊戲對象

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

 

    void Start(){

        GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);

 

        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        cube.transform.position = new Vector3(0, 0.5F, 0);

 

        GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        sphere.transform.position = new Vector3(0, 1.5F, 0);

 

        GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);

        capsule.transform.position = new Vector3(2, 1, 0);

 

        GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

        cylinder.transform.position = new Vecto3r(-2, 1, 0);

 

    }    //立鑽哥哥:void Start(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D5.2、Find

++D5.2、Find

++D5.2、Find

++++立鑽哥哥:查找

static GameObject Find(string name);

++++找到並返回一個名字爲name的遊戲物體

++++如果以name爲名字的遊戲物體沒有被找到,則返回空;如果name中包含/字符,這個名稱將被視作一個hierarchy中的路徑名;這個函數只返回活動的遊戲物體

++++除非迫不得已,建議不要在每一幀中使用這個函數;可以在開始的時候用一個成員變量來緩存結果或者使用GameObject.FindWithTag函數

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public GameObject hand;

 

    void MyTestFunc(){

        hand = GameObject.Find(MyHand);

        hand = GameObject.Find(/MyHand);

        hand = GameObject.Find(/Monster/Arm/MyHand);

        hand = GameObject.Find(Monster/Arm/MyHand);

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

//立鑽哥哥:在Start()裏查找MyHand物體,並在每幀旋轉它

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    private GameObject hand;

 

    void Start(){

        hand = GameObject.Find(/Monster/Arm/MyHand);

    }    //立鑽哥哥:void Start(){}

 

    void Update(){

        hand.transform.Rotate(0, 100 * Time.deltaTime, 0);

    }    //立鑽哥哥:void Update(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D5.3、FindGameObjectsWithTag

++D5.3、FindGameObjectsWithTag

++D5.3、FindGameObjectsWithTag

++++立鑽哥哥:通過標籤查找遊戲對象列表

static GameObject[] FindGameObjectsWithTag(string tag);

++++[tag]:用於搜索對象標籤的名稱

++++返回具體tag標籤的激活的遊戲對象列表,如果沒有找到則爲空

++++標籤必須在使用之前到標籤管理器裏面聲明;如果標籤不存在或爲空字符串或傳遞null作爲標籤,將拋出Unity異常

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public GameObject respawnPrefab;

    public Object respawns;

 

    void Start(){

        if(respawns == null){

            respawns = GameObject.FindGameObjectsWithTag(MyRespawn);

        }

 

        foreach(Object respawn in respawns){

            Instantiate(respawnPrefab, respawn.transform.position, respawn.transform.rotation) as GameObject;

        }

    }    //立鑽哥哥:void Start(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    

    GameObject MyFindClosestEnemy(){

        GameObject[] gos;

        gos = GameObject.FindGameObjectsWithTag(MyEnemy);

 

        GameObject closest;

        float distance = Mathf.Infinity;

        Vector3 position = transform.position;

 

        foreach(GameObject go in gos){

            Vector3 diff = go.transform.position - position;

            float curDistance = diff.sqrMagnitude;

        

            if(curDistance < distance){

                closest = go;

                distance = curDistance;

            }

        }    //立鑽哥哥:foreach(){}

 

        return closest;

    }    //立鑽哥哥:GameObject MyFindClosestEnemy(){}

 

    void MyTestFunc(){

        Debug.Log(MyFindClosestEnemy().name);

    }    //立鑽哥哥:void MyTestFunc(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    

    void Start(){

        GameObject[] gos;

        gos = GameObject.FindGameObjectsWithTag(MyFred);

 

        if(gos.Length == 0){

            Debug.Log(立鑽哥哥:No game objects are tagged with MyFred.);

        }

    }    //立鑽哥哥:void Start(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

++D5.4、FindWithTag

++D5.4、FindWithTag

++D5.4、FindWithTag

++++立鑽哥哥:查找標籤

static GameObject FindWithTag(string tag);

++++[tag]:要搜索的標籤

++++返回標記爲tag的一個遊戲對象,如果沒有找到對象則爲空

++++標籤必須在使用之前到標籤管理器裏面聲明;如果標籤不存在或爲空字符串或傳遞null作爲標籤,將拋出Unity異常

using UnityEngine;

using System.Collections;

using YanlzXREngine;

 

public class YanlzGameObject : MonoBehaviour{

    public GameObject respawnPrefab;

    public GameObject respawn;

 

    void Start(){

        if(respawn == null){

            respawn = GameObject.FindWithTag(MyRespawn);

        }

 

        Instantiate(respawnPrefab, respawn.transform.position, respawn.transform.rotation) as GameObject;

    }    //立鑽哥哥:void Start(){}

 

}    //立鑽哥哥:public class YanlzGameObject{}

 

 

 

 

 

 

 

#F6、立鑽哥哥對GameObject遊戲物體的拓展

#F6、立鑽哥哥對GameObject遊戲物體的拓展

++++【Unity API】分類:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

 

 

 

 

@@提示:有些博客可能只是開了頭,如果感興趣的同學,可以“點贊”或“評論區留言”,只要關注的同學多了,那就會繼續完善喲!(“++==”,表示沒有寫完的,如果關注度不高就不完善了;“++ok++”,表示此篇博客已經完成,是階段性完整的!)

 

 

++++VR雲遊戲=Unity+SteamVR+雲技術+5G+AI;(說明:AI人工智能不是我們的主要研究技術,只是瞭解一下,領略一下有風的感覺!但是,VR是我們的研究重點

++++【Unity API】分類:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html

++++【Unity開發基礎】分類:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html

++++【Linux系統編程】分類:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html

++++【C++C鑄就生存利器】分類:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html

++++【人工智能AI2026】分類:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html

++++【立鑽哥哥CSDN空間】:https://blog.csdn.net/VRunSoftYanlz/

 

 

 

 

 

 

【XR遊戲開發QQ羣:784477094

++立鑽哥哥推薦的拓展學習鏈接(Link_Url)

立鑽哥哥推薦的拓展學習鏈接(Link_Url)

++++立鑽哥哥Unity 學習空間: http://blog.csdn.net/VRunSoftYanlz/

++++虛擬現實VR資訊: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846

++++HTC_VIVE開發基礎https://blog.csdn.net/VRunSoftYanlz/article/details/81989970

++++Oculus雜談https://blog.csdn.net/VRunSoftYanlz/article/details/82469850

++++Oculus安裝使用https://blog.csdn.net/VRunSoftYanlz/article/details/82718982

++++Unity+SteamVR=>VRhttps://blog.csdn.net/VRunSoftYanlz/article/details/88809370

++++Unity減少VR暈眩症https://blog.csdn.net/VRunSoftYanlz/article/details/89115518

++++SteamVR簡介https://blog.csdn.net/VRunSoftYanlz/article/details/86484254

++++SteamVR腳本功能分析https://blog.csdn.net/VRunSoftYanlz/article/details/86531480

++++SteamVR2.0開發指南https://blog.csdn.net/VRunSoftYanlz/article/details/86618187

++++SteamVR2.2.0開發指南https://blog.csdn.net/VRunSoftYanlz/article/details/88784527

++++SteamVR2.2.0快速入門https://blog.csdn.net/VRunSoftYanlz/article/details/88833579

++++SteamVR2.2.0交互系統https://blog.csdn.net/VRunSoftYanlz/article/details/89199778

++++SteamVR2.2.0傳送機制https://blog.csdn.net/VRunSoftYanlz/article/details/89390866

++++SteamVR2.2.0教程(一)https://blog.csdn.net/VRunSoftYanlz/article/details/89324067

++++SteamVR2.2.0教程(二)https://blog.csdn.net/VRunSoftYanlz/article/details/89894097

++++SteamVR_Skeleton_Poserhttps://blog.csdn.net/VRunSoftYanlz/article/details/89931725

++++SteamVR實戰之PMCorehttps://blog.csdn.net/VRunSoftYanlz/article/details/89463658

++++SteamVR/Extrashttps://blog.csdn.net/VRunSoftYanlz/article/details/86584108

++++SteamVR/Inputhttps://blog.csdn.net/VRunSoftYanlz/article/details/86601950

++++OpenXR簡介https://blog.csdn.net/VRunSoftYanlz/article/details/85726365

++++VRTK雜談https://blog.csdn.net/VRunSoftYanlz/article/details/82562993

++++VRTK快速入門(雜談)https://blog.csdn.net/VRunSoftYanlz/article/details/82955267

++++VRTK官方示例(目錄)https://blog.csdn.net/VRunSoftYanlz/article/details/82955410

++++VRTK代碼結構(目錄)https://blog.csdn.net/VRunSoftYanlz/article/details/82780085

++++VRTK(SceneResources)https://blog.csdn.net/VRunSoftYanlz/article/details/82795400

++++VRTK_ControllerEventshttps://blog.csdn.net/VRunSoftYanlz/article/details/83099512

++++VRTK_InteractTouchhttps://blog.csdn.net/VRunSoftYanlz/article/details/83120220

++++虛擬現實行業應用https://blog.csdn.net/VRunSoftYanlz/article/details/88360157

++++Steam平臺上的VRhttps://blog.csdn.net/VRunSoftYanlz/article/details/88960085

++++Steam平臺熱銷VRhttps://blog.csdn.net/VRunSoftYanlz/article/details/89007741

++++VR實驗:以太網幀的構成https://blog.csdn.net/VRunSoftYanlz/article/details/82598140

++++實驗四:存儲器擴展實驗https://blog.csdn.net/VRunSoftYanlz/article/details/87834434

++++FrameVR示例V0913https://blog.csdn.net/VRunSoftYanlz/article/details/82808498

++++FrameVR示例V1003https://blog.csdn.net/VRunSoftYanlz/article/details/83066516

++++SwitchMachineV1022https://blog.csdn.net/VRunSoftYanlz/article/details/83280886

++++PlaySceneManagerV1022https://blog.csdn.net/VRunSoftYanlz/article/details/83280886

++++Unity5.x用戶手冊https://blog.csdn.net/VRunSoftYanlz/article/details/81712741

++++Unity面試題ABChttps://blog.csdn.net/vrunsoftyanlz/article/details/78630687

++++Unity面試題Dhttps://blog.csdn.net/VRunSoftYanlz/article/details/78630838

++++Unity面試題Ehttps://blog.csdn.net/vrunsoftyanlz/article/details/78630913

++++Unity面試題Fhttps://blog.csdn.net/VRunSoftYanlz/article/details/78630945

++++Cocos2dx面試題https://blog.csdn.net/VRunSoftYanlz/article/details/78630967

++++禪道[zentao]https://blog.csdn.net/VRunSoftYanlz/article/details/83964057

++++Lua快速入門篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818

++++Lua快速入門篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502

++++Lua快速入門篇(基礎概述)https://blog.csdn.net/VRunSoftYanlz/article/details/81041359

++++框架知識點https://blog.csdn.net/VRunSoftYanlz/article/details/80862879

++++遊戲框架(UI框架夯實篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80781140

++++遊戲框架(初探篇)https://blog.csdn.net/VRunSoftYanlz/article/details/80630325

++++.Net框架設計https://blog.csdn.net/VRunSoftYanlz/article/details/87401225

++++從零開始學架構https://blog.csdn.net/VRunSoftYanlz/article/details/88095895

++++設計模式簡單整理https://blog.csdn.net/vrunsoftyanlz/article/details/79839641

++++專題:設計模式(精華篇)https://blog.csdn.net/VRunSoftYanlz/article/details/81322678

++++U3D小項目參考https://blog.csdn.net/vrunsoftyanlz/article/details/80141811

++++Unity小遊戲算法分析https://blog.csdn.net/VRunSoftYanlz/article/details/87908365

++++Unity案例(Vehicle)https://blog.csdn.net/VRunSoftYanlz/article/details/82355876

++++UML類圖https://blog.csdn.net/vrunsoftyanlz/article/details/80289461

++++PowerDesigner簡介https://blog.csdn.net/VRunSoftYanlz/article/details/86500084

++++Unity知識點0001https://blog.csdn.net/vrunsoftyanlz/article/details/80302012

++++Unity知識點0008https://blog.csdn.net/VRunSoftYanlz/article/details/81153606

++++U3D_Shader編程(第一篇:快速入門篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80372071

++++U3D_Shader編程(第二篇:基礎夯實篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80372628

++++Unity引擎基礎https://blog.csdn.net/vrunsoftyanlz/article/details/78881685

++++Unity面向組件開發https://blog.csdn.net/vrunsoftyanlz/article/details/78881752

++++Unity物理系統https://blog.csdn.net/vrunsoftyanlz/article/details/78881879

++++Unity2D平臺開發https://blog.csdn.net/vrunsoftyanlz/article/details/78882034

++++UGUI基礎https://blog.csdn.net/vrunsoftyanlz/article/details/78884693

++++UGUI進階https://blog.csdn.net/vrunsoftyanlz/article/details/78884882

++++UGUI綜合https://blog.csdn.net/vrunsoftyanlz/article/details/78885013

++++Unity動畫系統基礎https://blog.csdn.net/vrunsoftyanlz/article/details/78886068

++++Unity動畫系統進階https://blog.csdn.net/vrunsoftyanlz/article/details/78886198

++++Navigation導航系統https://blog.csdn.net/vrunsoftyanlz/article/details/78886281

++++Unity特效渲染https://blog.csdn.net/vrunsoftyanlz/article/details/78886403

++++Unity數據存儲https://blog.csdn.net/vrunsoftyanlz/article/details/79251273

++++Unity中Sqlite數據庫https://blog.csdn.net/vrunsoftyanlz/article/details/79254162

++++WWW類和協程https://blog.csdn.net/vrunsoftyanlz/article/details/79254559

++++Unity網絡https://blog.csdn.net/vrunsoftyanlz/article/details/79254902

++++Unity資源加密https://blog.csdn.net/VRunSoftYanlz/article/details/87644514

++++PhotonServer簡介https://blog.csdn.net/VRunSoftYanlz/article/details/86652770

++++編寫Photon遊戲服務器https://blog.csdn.net/VRunSoftYanlz/article/details/86682935

++++C#事件https://blog.csdn.net/vrunsoftyanlz/article/details/78631267

++++C#委託https://blog.csdn.net/vrunsoftyanlz/article/details/78631183

++++C#集合https://blog.csdn.net/vrunsoftyanlz/article/details/78631175

++++C#泛型https://blog.csdn.net/vrunsoftyanlz/article/details/78631141

++++C#接口https://blog.csdn.net/vrunsoftyanlz/article/details/78631122

++++C#靜態類https://blog.csdn.net/vrunsoftyanlz/article/details/78630979

++++C#中System.String類https://blog.csdn.net/vrunsoftyanlz/article/details/78630945

++++C#數據類型https://blog.csdn.net/vrunsoftyanlz/article/details/78630913

++++Unity3D默認的快捷鍵https://blog.csdn.net/vrunsoftyanlz/article/details/78630838

++++遊戲相關縮寫https://blog.csdn.net/vrunsoftyanlz/article/details/78630687

++++UnityAPI.Rigidbody剛體https://blog.csdn.net/VRunSoftYanlz/article/details/81784053

++++UnityAPI.Material材質https://blog.csdn.net/VRunSoftYanlz/article/details/81814303

++++UnityAPI.Android安卓https://blog.csdn.net/VRunSoftYanlz/article/details/81843193

++++UnityAPI.AndroidJNI安卓JNIhttps://blog.csdn.net/VRunSoftYanlz/article/details/81879345

++++UnityAPI.Transform變換https://blog.csdn.net/VRunSoftYanlz/article/details/81916293

++++UnityAPI.WheelCollider輪碰撞器https://blog.csdn.net/VRunSoftYanlz/article/details/82356217

++++UnityAPI.Resources資源https://blog.csdn.net/VRunSoftYanlz/article/details/83155518

++++JSON數據結構https://blog.csdn.net/VRunSoftYanlz/article/details/82026644

++++CocosStudio快速入門https://blog.csdn.net/VRunSoftYanlz/article/details/82356839

++++Unity企業內訓(目錄)https://blog.csdn.net/VRunSoftYanlz/article/details/82634668

++++Unity企業內訓(第1講)https://blog.csdn.net/VRunSoftYanlz/article/details/82634733

++++Unity企業內訓(第2講)https://blog.csdn.net/VRunSoftYanlz/article/details/82861180

++++Unity企業內訓(第3講)https://blog.csdn.net/VRunSoftYanlz/article/details/82927699

++++Unity企業內訓(第4講)https://blog.csdn.net/VRunSoftYanlz/article/details/83479776

++++Unity企業內訓(第5講)https://blog.csdn.net/VRunSoftYanlz/article/details/83963811

++++Unity企業內訓(第6講)https://blog.csdn.net/VRunSoftYanlz/article/details/84207696

++++鑽哥帶您瞭解產品原型https://blog.csdn.net/VRunSoftYanlz/article/details/87303828

++++插件<Obi Rope>https://blog.csdn.net/VRunSoftYanlz/article/details/83963905

++++計算機組成原理(教材篇)https://blog.csdn.net/VRunSoftYanlz/article/details/82719129

++++5G接入:雲計算和霧計算https://blog.csdn.net/VRunSoftYanlz/article/details/88372718

++++雲計算通俗講義https://blog.csdn.net/VRunSoftYanlz/article/details/88652803

++++立鑽哥哥Unity 學習空間: http://blog.csdn.net/VRunSoftYanlz

--_--VRunSoft:lovezuanzuan--_--

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章