29606人加入学习
(126人评价)
Unity API常用方法和类详细讲解(基于Unity5.6)
价格 免费
承诺服务

GameObject独有的静态方法

静态方法都是首字母大写的

Find():根据名字查找,遍历场景中的所有游戏物体,用的少

FindGameObjectWithTag():通过标签来查找相同标签游戏物体

FindGameObjectsWithTag():通过标签来查找所有相同标签游戏物体

//Find
GameObject go = GameObject.Find("Main Camera");
go.SetActive(false);//验证上一步是否运行
//FindGameObjectsWithTag
GameObject[] gos = GameObject.FindGameObjectsWithTag("MainCamera");
gos[0].SetActive(false);

[展开全文]

GameObject独有的静态方法:

  •  activeHerachy
  • activeSelf
  • Layer
  • Scene
  • tag
  • CreatPrimitive
  • Find
  • FindGameObjectsWithTag
  • FindWithTag

GameObject.Find(Main Camera);

GameObject.FindGameObjectsWithTag("MainCamera");

[展开全文]

1、Find根据名字来查找

FindGameObjectsWithTag、FindWithTag根据标签来查找的

2、Add  Tag出可以添加新的标签

[展开全文]

siki学院:www.sikiedu.com


如何看Unity文档和API手册
Unity中的事件方法
Help->Unity Manual/Scripting Reference

Time.deltaTime 当前帧运行占用的时间
    realtimeSinceStartup 从游戏开始到现在的总时间
    smoothDeltaTime 
    fixedTime
    timeScale

GameObject游戏物体
    activeSelf 自身的属性(若某一游戏物体有一个子物体,如果该游戏物体被禁用了,则子物体的activeSelf可以为true)
    activeInHierarchy 在Hierachy面板中的属性(如上例,该子物体的activeInHierarchy一定为false)
    GameObject go.activeInHierarchy
    GameObject go.SetActive(true/false);通过该语句设置游戏物体的activeInHierarchy属性
    tag 标签   区分不同的游戏物体
    GameObject go.tag
    
构造GameObject的方法
    1,new 直接实例化
    GameObject go = new GameObject("Cube");
    2,Instantiate  可以根据一个prefab或者另外一个游戏物体克隆
    GameObject.Instantiate(prefab);
    3,CreatePrimitive  创建原始的集合体
    GameObject.CreatePrimitive(PrimitiveType.Plane);
    GameObject go = GameObject.CreatPrimitive(PrimitiveType.cube)

AddComponent 添加组件
    GameObject go.AddComponent<Collider 2D>();

Tranform  任何游戏物体都会有的一个组件,该组件控制着该游戏物体最基本的属性(坐标,旋转角度,大小)
     该组件不可被删除

    Object Destroy 游戏物体销毁
    Destroy/DestoryImmediate  推荐使用Destroy 
    Destory可以销毁游戏物体也可以销毁游戏物体的组件
    Destroy(gameObject, 5);  销毁游戏物体
    Destroy(GetComponent<Rigidbody>()); 销毁游戏物体组件
    DontDestroyOnLoad 切换场景时,该游戏物体不会被销毁

GameObject和Component 相同点和区别


游戏物体或组件的查找
    GameObject.Find
    GameObject go = GameObject.Find("Main Camera");该方法的返回值是一个GameObject类型变量,注意括号内是一个字符串类型
    FindObjectOfType(可以直接调用也可以用GameObject调用)往往返回的是一个游戏物体或某一组件类型的变量
    FindObjectsOfType (同上)往往返回的是一个游戏物体或组件数组类型的变量
    上述两个方法不会查找未激活的游戏物体
    Light light = FindObjectOfType<Light>();(查找到之后就可以对查找到的物体或组件进行控制)
     Camera cam = (Camera)FindObjectOfType(typeof(Camera));
    Transform[] ts = FindObjectsOfType<Transform>();
    FindWithTag
    transform.Find

GetComponet(s)InChildren


Mathf
Deg2Rad
Infinity

Clamp
ClosestPowerOfTwo
Lerp
LerpAngle
MoveTowards
PingPong
Round
SmoothDamp

Input
GetKey..
GetAxis
OnMouse

Vector2

Vector3

Random 随机整数 随机小数的生成
什么是随机种子

Quaternion
什么是四元数
Quaternion.LookRotation
Euler
Lerp
Slerp

Rigibody
mass velocity
useGravity isKinematic

AddForque
AddForce
MovePosition


Camera
mainCamera
ScreenPointToRay
ScreenToWorldPoint
WorldToScreenPoint

Application.dataPath

streamingAssetsPath
persistentDataPath
temporaryCachePath

companyName
idenifier
installerName
isEditor
isFocused
isMobilePlatform
isPlaying
is

场景加载
SceneManager
LoadScene LoadSceneAsync
GetActiveScene

CaptureScreenshot
 

[展开全文]

activeinHierachy

acitiveself

layer

scene

tag

通过标签查找比通过名字查找节省性能

 

[展开全文]

GameObject的静态方法

layer 获取游戏所在的层

scene 获取游戏的场景

静态查找方法

CreatePrimitive 创建某个基本体

Find 根据名字进行查找 遍历游戏场景当中的所有物体

FindGameObjectsWithTag 根据标签进行查找(查找游戏当中所有标签名称相同的物体)返回的时数组

FindWithTag 根据标签进行查找(当游戏当中有多个相同tag名时,只返回一个)

1.GameObject go=GameObject.Find("类名");

go.SetActive(false);

2.GameObject[] go=Gameobject.FindGameObjectsWithTag("标签名");

go.SetActive(false);

3.GameObject go=GameObject.FindGameObjectWithTag("标签名");

go.SetActive(false);

公共方法

 

[展开全文]

GameObject独有的静态方法

activeInHierarchy

activeself

layer

tag

静态查找

GameObject.Find("名字"); 遍历耗费性能。

GameObject.FindGameObjectWithTag("tag");效率高。

GameObject.FindGameObjectsWithTag("tag");

 

[展开全文]

GameObject独有的静态方法:

变量:

activeInHierarchy(游戏物体的状态:默认为true激活状态)(表示父物体)

SetActive(设置游戏物体的激活与禁用)

true为激活false为禁用;

layer:获取游戏所在的层;

scence:获取游戏所在的场景;

方法(静态方法)

CreatePrimitive:创建原始游戏物体;

Find: 根据名字查找游戏物体;(尽量不要再update中调用,少在start中调用)

FindWithTag:通过标签查找游戏物体,返回第一个;

FindGameObjectsWithTag:通过标签查找游戏物体,返回第所有,(可能是一个数组);

 

 

[展开全文]

012-GameObject独有的静态方法

 

[展开全文]

Find

CreatePrimitve

FindGameObjectWithTag

FindWithTag

FindGameObjectsWithTag

[展开全文]

 GameObject.Find("Main Camera");

 GameObject.FindGameObjectsWithTag("Main Camera");

[展开全文]