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

1.创建游戏物体的三种方法:

new一个

Instantiate实例化一个

GameObject.CreatePrimitive()创建基本图形

[展开全文]

1.frameCount:从游戏开始运行的帧数

2.timeScale:值为零暂停,值为1正常速度运行,值为2就是2倍速。

[展开全文]

1.Vector2.Nomalize():把向量自身单位化

2.Vector2.Angel():取两个向量间的夹角

3.Vector2.ClampMagnitude(Vector2 vector,float maxLength);将向量如果长度小于maxLength那就保持自身,如果大于maxLength那就变成maxLength。

4.Vector2.Distance(Vector2 a,Vector b):取得a指向b的向量的长度。

5.Vector2.Lerp(Vector2 a,Vector b,float t):对象量插值运算。

6.Vector2.MoveTowards(Vector2 current,Vector2 target,float maxDistanceDelta):移向目标

7.Vector2.Set():给向量赋值

[展开全文]

1.Vector2是结构体,是值类型,要整体赋值。

[展开全文]

1.Input.MousePosition:鼠标在屏幕的位置

2.Input.AnyKeyDown:获取任何按键按下

[展开全文]

Mathf.MoveTowards(a,b,t):速度为t从a匀速递加到b。如果t为负数,那就从开始远离b

[展开全文]

1.yield return new WaitForSeconds(3);

让携程方法暂停三秒再向下执行

[展开全文]

sharedMesh

引用已有的mesh

Mesh

创建mesh的一个新实例,并赋值

If no mesh is assigned to the mesh filter a new mesh will be created and assigned.

If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. Once mesh property is queried, link to the original shared mesh is lost and MeshFilter.sharedMesh property becomes an alias to mesh.

因此mesh属性总是保证不和其他对象共享mesh实例的引用

 

[展开全文]

public bool SimpleMove(Vector3 speed);

设置速度移动,不是设置位置增量移动。

public CollisionFlags Move(Vector3 motion);

设置位置增量进行移动

[展开全文]

addForce默认为物体施加一个,给定力度的,持续时间是fixedDeltaTime的,力脉冲。

Reference:

ForceMode.Force will actually use fixedDeltaTime internally.

 

速度的变化取决于力和力作用的时间。

 

addForce调用,没有设置时间,那么

力作用时间到底是多少?

fixedDeltaTime。

 

因此,持续的施加力,要在fixedupdate里调用,才精确。

 

目测应该区别不大。

[展开全文]

CloestPowerOfTwo

求最接近给定数字的平方数

例如,给定19,最接近的是16,4的平方

[展开全文]

1.Destory既可以销毁游戏物体也可以销毁组件。

Destroy方法可以延时执行:Destroy(gameObject,5);

2.DontDestoryOnLoad(transform.gameObject);由A场景切换到B场景,A场景里的游戏物体都会被销毁然后加载B场景里的游戏物体,如果A场景中某个游戏物体调用此方法,该物体不会被销毁,无论怎么切换场景这个游戏物体始终存在。

3.根据类型找游戏物体,不查找未激活的游戏物体

FindObjectOfType

FindObjectsOfType

4.DestoryImmediate:立刻销毁

[展开全文]

for 死循环
for(;;)
{

循环结构体
 

if(判断结构体){

break;

}

 

}

[展开全文]

1.Awake方法

2.FixedUpdate每秒调用固定次数,每秒固定调用60次

3.Update和LateUpdate是一帧调用一次,每秒有多少帧和电脑配置有关

4.FixedUpdate在Update前调用,Update在LateUpdate前调用

[展开全文]

InvokeRepeating(方法,xmiao开始调用)

[展开全文]

1.print (等同于Debug.log) 只能在MonoBehaviour中调用  Debug.log是可在所有地方调用

2.isActiveAndEnabled 判断组件是否激活

3.组件通过enabled来设置组件的激活和禁用,而物体是setActive。

4.组件标签获取的是物体标签

5.gameObject 获取到组件所在游戏物体

[展开全文]

MonoBehaviour

 

1.component和GameObject方法一样但没有放在基类中

2.addComponent是GameObject独有的   

3.MonoBehaviour 所有脚本的基类

4.ExecuteInEditMode。编辑模式下脚本也可运行 类似注解 加在类上, 编辑模式上也可调用

5.invoke 调用某个方法  invokeRepeating 重复调用某个方法 CancelInvoke取消调用某个方法

 

 

[展开全文]

component和GameObject方法一样但没有放在基类中

getComponentInChildren 得到组件,多个相同组件,只得到第一个

getComponentsInChildren 得到所有组件 包括自己与子组件)

getComponentInParent

getComponentsInParent 

[展开全文]