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

transform每个物体都有,不能被移除。

tag区分场景中物体。

activeInHierarchy判断物体是否处于激活状态。

go.SetActive(true),用于激活关闭/打开。

[展开全文]

乘以Time.deltatime.控制动画、运动相关。

TimeScale=0用于暂停游戏。

TimeScale=0.5可用于慢动作回放。

(deltatime一般都会×TimeScale,TimeScale默认1)

Time.realtimeSinceStartUp可用于性能测试。

(time2-time1)即可

[展开全文]

一个游戏有多个场景组成,一个场景有多个游戏物体(GameObject)组成,一个游戏物体又多个组件组成(Component)。

组件:Transform,Rigidboy,MeshRender,MeshFilter,

Collider,NavmeshAgent,Animation,Animator,自定义脚本(Script)

[展开全文]

英语发音稍微有点迷哈哈哈,sderp笑死我了

[展开全文]

GameObject.BroadcastMessage

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

Description

Calls the method named methodName on every MonoBehaviour in this game object or any of its children.

The receiving method can choose to ignore parameter by having zero parameters. If options is set to SendMessageOptions.RequireReceiver an error is printed when the message is not picked up by any component.

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        /// Calls the function ApplyDamage with a value of 5
        /// // Every script attached to the game object and all its children
        // that has a ApplyDamage function will be called.
        gameObject.BroadcastMessage("ApplyDamage", 5.0);
    }
}



public class Example2 : MonoBehaviour
{
    public void ApplyDamage(float damage)
    {
        print(damage);
    }
}

 

GameObject.SendMessage

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

Parameters

methodName The name of the method to call.
value An optional parameter value to pass to the called method.
options Should an error be raised if the method doesn't exist on the target object?

Description

Calls the method named methodName on every MonoBehaviour in this game object.

The receiving method can choose to ignore the argument by having zero parameters. If options is set to SendMessageOptions.RequireReceiver an error is printed if the message is not picked up by any component.

Note that messages will not be sent to inactive objects (ie, those that have been deactivated in the editor or with the SetActive function).

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Calls the function ApplyDamage with a value of 5
        // Every script attached to the game object
        // that has an ApplyDamage function will be called.
        gameObject.SendMessage("ApplyDamage", 5.0);
    }
}

public class Example2 : MonoBehaviour
{
    public void ApplyDamage(float damage)
    {
        print(damage);
    }
}

 

GameObject.SendMessageUpwards

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

Parameters

methodName The name of the method to call.
value An optional parameter value to pass to the called method.
options Should an error be raised if the method doesn't exist on the target object?

Description

Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.

The receiving method can choose to ignore the argument by having zero parameters. If options is set to SendMessageOptions.RequireReceiver an error is printed when the message is not picked up by any component.

Note that messages will not be sent to inactive objects (ie, those that have been deactivated in the editor or with the SetActive function).

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Calls the function ApplyDamage with a value of 5
        gameObject.SendMessage("ApplyDamage", 5.0);
    }
}

public class Example2 : MonoBehaviour
{
    public void ApplyDamage(float damage)
    {
        print(damage);
    }
}

 

 

 

 

 

[展开全文]

变量:

magnitude:获取向量;

mormalized:把坐标值都变为1;

[展开全文]

getbutton("虚拟按键名");

虚拟按键可对应多个物理按键;

如 fire1 ;

[展开全文]

FlexdUpdate  每秒(60)就60次

OnTrigger  触发器

OnCollision  碰撞器

OnMouse XX  输入事件 鼠标操作有关的事件

Scene rendering  场景渲染有关的

Delteime  延迟事件

deltatime 每一帧的时间间隔

FrameCount 帧数

 

游戏运行一共占用时间【

time

timeSinceleveILoad

fixedTime】

【realtimeSinceStartup 暂停还会记时】

【timeScale  时间比例】

Vector3三位矢量

forward前进

 

构造方法

Instantiate   实例化

CreatePrimitive   创造基本元素

添加组件

AddComponent

[展开全文]

FlexdUpdate  每秒(60)就60次

OnTrigger  触发器

OnCollision  碰撞器

OnMouse XX  输入事件 鼠标操作有关的事件

Scene rendering  场景渲染有关的

Delteime  延迟事件

deltatime 每一帧的时间间隔

FrameCount 帧数

realtimeSinceStartup 游戏开始到现在占用的时间

游戏运行一共占用时间【

time

timeSinceleveILoad

fixedTime】

【realtimeSinceStartup 暂停还会记时】

【timeScale  时间比例】

Vector3三位矢量

forward前进

 

构造方法

Instantiate

CreatePrimitive

[展开全文]

FlexdUpdate  每秒(60)就60次

OnTrigger  触发器

OnCollision  碰撞器

OnMouse XX  输入事件 鼠标操作有关的事件

Scene rendering  场景渲染有关的

Delteime  延迟事件

deltatime 每一帧的时间间隔

FrameCount 帧数

realtimeSinceStartup 游戏开始到现在占用的时间

游戏运行一共占用时间【

time

timeSinceleveILoad

fixedTime】

【realtimeSinceStartup 暂停还会记时】

【timeScale  时间比例】

Vector3三位矢量

forward前进

[展开全文]

FlexdUpdate  每秒(60)就60次

OnTrigger  触发器

OnCollision  碰撞器

OnMouse XX  输入事件 鼠标操作有关的事件

Scene rendering  场景渲染有关的

Delteime  延迟事件

deltatime 每一帧的时间间隔

FrameCount 帧数

realtimeSinceStartup 游戏开始到现在占用的时间

游戏运行一共占用时间【

time

timeSinceleveILoad

fixedTime】

【realtimeSinceStartup 暂停还会记时】

【timeScale  时间比例】

 

 

 

   

[展开全文]

rigidbody.MoveRotation(Quaternion.Slerp(player.transform.position+Vector3.forward*Time.deltaTime));

 

 

[展开全文]

Time.timeScale,可以用于暂停游戏(对Time.deltaTime全都会影响)

Time.deltaTime用于表示每一帧的时间

Time.realtimeSinceStartup可用与测试方法对性能的消耗( 表示运行的时间)

 

[展开全文]

Time.deltaTime  指一帧的运行时间,根据电脑配置和代码运行效率这一帧的运行时间会发生变化

 

 

Time.fixedDeltaTime  指一帧的运行时间,这一帧的运行时间是固定的,默认是0.02s,可以在Edit->Project Settings->Time中的Fixed Timestep修改。

[展开全文]

如果调用的是普通方法,会等普通方法执行完后向下执行。

调用的是协程方法,调用后就会继续运行。

[展开全文]

Destroy():可以销毁游戏物体和组件;也可等待一段时间后销毁

DontDestroyOnLoad(gameobject):设置共享的游戏物体,再调整场景是不销毁

FindObjectOfType()根据类型获取组件

FindObjectsOfType()根据类型返回组件数组

[展开全文]
coroutine methods

public GameObject cube;

void start() {

StartCoroutine(changeColor());

}

IEnumerator changeColor(){

cube.GetComponent<MeshRenderer>().material.color = Color.blue;

yield return null;

}

 

 

[展开全文]

生成随机数

Random.Range

Random.InitState(int):给予生成随机数的种子

[展开全文]

anyKeyDown:有任何键按下就返回true

mousePosition:f返回鼠标在屏幕的像素坐标

 

[展开全文]

授课教师

SiKi学院老师

课程特色

图文(1)
下载资料(2)
视频(71)