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

Destroy()可以销毁object也可以销毁组件

DontDestroyOnLoad()是在场景转化的时候将上一个场景指定的object保留下来场景   切换时object始终存在

游戏组件.enabled = false 这个可以禁用一个gameobject的一个组件 前提是之前要获取 

findobjectsoftype<>全局查找指定的组件发回值是一个数组:Transform[] ts = FindObjectOfType<Transform>();不查找未激活的

[展开全文]
半只狗 · 2018-05-06 · 该任务已被删除 1

我们通常将运动相关的放在fixedupdate()

[展开全文]
乐ii · 2018-09-19 · 该任务已被删除 1

先写过几个最简单的小游戏再看这个课程,如打砖块。对一些常用函数有个印象,懂得unity的基本操作。

[展开全文]

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);
    }
}

 

 

 

 

 

[展开全文]

从transform获取的name是游戏物体上的name 与GameObject上的name返回值相同

[展开全文]
Jarchi · 2018-05-10 · 该任务已被删除 1

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

[展开全文]

​​​​​​​(向下)GameObject.BroadcastMessage(方法): 执行自己和自己的子物体的所有脚本的某一方法;

GameObjeectSendMessage(方法):只执行自己身上所有脚本的某一方法;

(向上)GameObject.SendMessageUnwords(方法):只执行自己和自己向上的所有父级的所有脚本的某一方法;

[展开全文]
小付 · 2018-11-27 · 该任务已被删除 1

创建游戏物体的三种方法

1、new 一个

2、Instantiate(prefab)//定制

3、CreatePrimitive(primitiveType.XXX)//

[展开全文]
muyuqianshan · 2017-06-09 · 该任务已被删除 1

代码时处女座鉴定完毕

[展开全文]
太阳神的宠儿 · 2018-06-05 · 该任务已被删除 1

Time

从 Unity 获取时间信息的接口。

静态变量

captureDeltaTime 减慢游戏播放时间,以便在帧之间保存屏幕截图。
captureFramerate Time.captureDeltaTime 的倒数。
deltaTime 完成上一帧所用的时间(以秒为单位)(只读)。
fixedDeltaTime 执行物理和其他固定帧率更新(如 MonoBehaviour 的 FixedUpdate)的时间间隔(以秒为单位)。
fixedTime 最近一次 FixedUpdate 已启动的时间(只读)。此为自游戏启动以来的时间(以秒为单位)。
fixedUnscaledDeltaTime 从上一个固定帧到当前固定帧的独立于 timeScale 的时间间隔(以秒为单位)(只读)。
fixedUnscaledTime 最近一次 FixedUpdate 已启动的独立于 TimeScale 的时间(只读)。此为自游戏启动以来的时间(以秒为单位)。
frameCount 已经过的总帧数(只读)。
inFixedTimeStep 如果在固定时间步长回调(如 MonoBehaviour 的 FixedUpdate)内调用,则返回 true,否则返回 false。
maximumDeltaTime 帧可以耗用的最长时间。物理和其他固定帧率更新(如 MonoBehaviour 的 FixedUpdate)将仅在每帧的该持续时间内执行。
maximumParticleDeltaTime 帧可以在粒子更新上耗用的最长时间。如果帧耗用的时间超过该值,则将更新拆分为多个较小的更新。
realtimeSinceStartup 游戏开始以来的实际时间(只读)。
smoothDeltaTime 经过平滑处理的 Time.deltaTime(只读)。
time 该帧开始的时间(只读)。此为自游戏启动以来的时间(以秒为单位)。
timeScale 时间流逝的标度。可用于慢动作效果。
timeSinceLevelLoad 该帧开始以来的时间(只读)。此为自加载上一个关卡以来的时间(以秒为单位)。
unscaledDeltaTime 从上一帧到当前帧的独立于 timeScale 的时间间隔(以秒为单位)(只读)。
unscaledTime 该帧的独立于 timeScale 的时间(只读)。此为自游戏启动以来的时间(以秒为单位)。
[展开全文]

MathfMoveToward

[展开全文]
我要糖 · 2019-03-24 · 该任务已被删除 1

代码段分析:

Ray ray = new Ray(transform.position,transform.forward);
bool isCollider = physics.Raycast(ray);

射线检测需要创建一个射线,指定一个点和方向

射线检测返回的是一个布尔值,用布尔型变量进行接收

再显示在控制台

问题解决:

设置的起点发射有可能和自身发生碰撞,所以最好把起点位置往前移动一些

Ray ray = new ray(transform.position+transform.forward,transform.forward);

一个transform.forward代表往前一米的意思

[展开全文]
漠Paranoid · 2019-01-20 · 该任务已被删除 1

代码段分析:

Physics.Raycast(ray,1);

一共有16种重载方法,有许多重复的,其中

第二种:有可以设置射线检测的长度大小的方法

第三种:out变量,可以传递碰撞到的信息及变量

需要设置,创建新的变量。

RaycastHit hit;

输出碰撞到的碰撞器,碰撞到的位置

Debug.Log(hit.collider);
Debug.Log(hit.point);

第五种:射线,长度,碰撞层(只和此层发生碰撞)

Physics.Raycast(ray,Mathf.Infinity,LayerMask.GetMask("Enemy1"));

 LayMask.GetMask("Enemy1","Enemy2","UI");

多个层发生碰撞的方法

第六种:射线,碰撞信息,长度

此后其他种均为起点,方向,长度,碰撞信息,碰撞层的混合类

问题:

还有一个类Siki教程里未明说

[展开全文]
漠Paranoid · 2019-01-20 · 该任务已被删除 1

cube.translate(vector3.forward,Time.deltaTime);//运动、动画

Time.realttiimeSinceStartup//性能测试

[展开全文]
XieAndwater · 2017-07-03 · 该任务已被删除 1

Unity文档

Scripting reference ----API文档

Unity Manual 手册

[展开全文]
cmcc红泥小火炉 · 2018-04-29 · 该任务已被删除 1

角色控制器

center:获取自身的位置

helgt:获取自身的高度

isGrounded;判断自身的位置

移动方法

Move

SlmpleMove

onControllerC olliderHit;移动时角色控制器碰撞到物体时会触发

characterController自带碰撞器

SimplMove,会模拟重力而Move则不会 

[展开全文]
苍云卷暮色 · 2019-03-27 · 该任务已被删除 1

1、公共方法

通过对象调用

CompareTag:比较标签的。

游戏物体由组件组成。

2、游戏物体间的消息发送和接收

BroadcastMessage:广播消息。不知道谁接收消息。传递方法名,所有的孩子都有可能接收到这个消息,如果孩子有这个方法这个方法就会被调用。

减少游戏之间的耦合性。

SendMessgae:发送消息只会给特定的物体,遍历该物体中的所有脚本调发送的方法名。

SendMessageUpwards:当前物体以及他的所有父亲物体,如果有该方法都会被调用。

 

[展开全文]
cherey · 2018-01-25 · 该任务已被删除 1

vecter2 是结构体,它里面的变量是值类型,,不是引用类型

[展开全文]
yinguilan · 2017-07-07 · 该任务已被删除 1

        Time.timeScale = 0.1f;
        float newX = Input.GetAxis("Horizontal");
        cube.transform.Translate(Vector3.right * newX);

timeScale可以加强使用效果

[展开全文]
浪迹天涯义 · 2017-12-28 · 该任务已被删除 1

1.创建游戏物体f的三种方法
new GameObject();括号里可以添加想要创建的物体类型例如
new GameObject("Cube");创建出一个正方体
GameObject.Instantiate();
实例化Prefabs或实例化游戏物体
GameObject.CreatePrimitive();
创建原始图形如:.GameObject.CreatePrimitive(PrimitiveType.Cube);
2.通过代码给游戏物体添加组件
 private GameObject object;
object.AddComponent<Rigidbody>();
通过代码给游戏物体j添加脚本
object.AddComponent<脚本名>();
3.GameObject游戏物体的常用类
GameObject.activeInHierarchy 物体是否处于激活状态(包括自身及子物体)
4.UnityEngine下Object的静态方法
Object.Destroy:
Destroy(gameobject,time);
Object.DontDestroyOnLoad:
DontDestroyOnLoad(transform.gameObject);(在进行场景之间转换时不会被销毁,会被带到下一个场景中)
Object.FindObjectOfType:
Object   a =FindObjectOfType(typeof(组件名))
Rigidbody  a=FindObjectOfType<Rigidbody>();
只返回第一个被检测到含有此组件的物体。不查找未激活的游戏物体
Object.FindObjectsOfType:
Object   a =FindObjectsOfType(typeof(组件名))
Rigidbody a=FindObjectsOfType<Rigidbody>();
将检测到的所有的含有此组件的物体都存在数组中。不查找未激活的游戏物体
5.查找方法
Find(比较耗费性能)
FindGameObjectsWithTag返回所有是次标签的物体返回数组
FindWithTag只返回第一个检测到的物体。
6.游戏物体间消息的发送和接收
GameObject.BroadcastMessage();包括其自身及其子物体
GameObject.SendMessage(); 不包括子物体
GameObject.SendMessageUpwards();包括其自身及其父物体
7.得到组件的各种方法函数

GetComponent;只会得到在游戏物体身上的第一个检测到的组件

GetComponent;会得到物体上所有的组件

GetComponentInChildren;会得到其自身及其子物体身上第一个检测到的相应的组件

GetComponentInParent;会得到其自身及其父物体身上第一个检测到的相应的组件

GetComponentsInChildren;会得到其自身及其子物体身上所有检测到的相应的组件

GetComponentsInParent;会得到其自身及其父物体身上所有检测到的相应的组件

8.Public Functions

Invoke;

Public void Invoke(string methodName,float time );可延时调用方法

CancelInvoke;取消所有调用的方法(仅适用于当前脚本,不影响其他脚本中相同方法的调用)

InvokeRepeating;重复调用方法

IsInvoking;判断方法是否正在被调用

协程:

1.返回值是IEnumerator

2.返回参数时使用yield return null/0。

3协程方法的调用:使用StartCoroutine(需要调用的协程方法的名字);

4暂停yield return new WaitForSeconds(需要暂停的时间);

例如:

IEnumerator Method(){

内容;

yied return null;

}

StartCoroutine();开启协程

StopCoroutine();关闭协程

StopAllCoroutine();

9.与鼠标相关事件函数OnMouseXXX

OnMouseDown();当鼠标按下时触发

OnMouseUp();当鼠标抬起时触发

OnMouseDrag();当鼠标已经按下但没有抬起时触发

OnMouseEnter();当鼠标在游戏物体身上但没有按下鼠标时触发

ONMouseExit();当鼠标离开游戏物体时触发

OnMouseOver();当鼠标在游戏物体身上时无论是鼠标按下或没有按下只要鼠标在游戏物体身上就触发。

10.Mathf里面的方法

Mathf.PI 圆周率

Mathf.Deg2Rad 将度数转变为弧度

Mathf.Rad2Deg 将弧度转成度数

Mathf.Epsilon 无限小的数

Mathf.Infinity 无限大的数

Mathf.Abs 绝对值

Mathf.Ceil 向上取整

如Mathf.Ceil(10);结果为10.

Mathf.Ceil(10.2f);结果为11.

Mathf.Ceil(-10);结果为-10.

Mathf.Ceil(-10.2f);结果为-10.

Mathf.Floor();向下取整。

Mathf.Clamp(float value,float min,flaot max); valur为自己定义的数值。如果value小于min则将value改为min,如果value大于min且小于max则value为自身值,如果value大于max则将value改为max。

Mathf.ClosesPowerOfTwo(int value);取离value最近的2的多次方

如Mathf.ClosesPowerOfTwo(3);返回4

Mathf.ClosesPowerOfTwo(7);返回8

Mathf.DeltaAngle();返回角度之间的最小夹角。如721°-360°=361°,其返回1°。

Mathf.Exp(float power);代表e的power次方

Mathf.Max(float a,float b);比较两个数中的最大值(float可换为int)

Mathf.Max(float[] value);比较数组中的最大值(float可换为int)

Mathf.Min(float a,float b);比较两个数中的最小值(float可换为int)

Mathf.Min(float[] value)比较数组中的最小值(float可换为int

Mathf.Pow(float a,float b);a的b次方。

Mathf.Sqrt();开平方根。

Mathf.Lerp(float a,float b,float t);插值运算 

t为a到b之间的距离的比率,如t=0.5时,返回值为(a+b)*0.5,t为0时,返回值为a,t为1时返回值为b;

Mathf.LerpAngle();角度的差值运算

 Mathf.MoveToWards(float a,float b,float t);

a初始 值,b目标值,t从a到b每帧所移动的距离。

Mathf.PingPong(float a,float b);返回值在0到b之间0为最小值,b为最大值,返回值随着a的增大在0到b之间往返。

11.Input

GetTouch()屏幕触摸

Input.anyKeyDown();按下任何键都会触发,包括鼠标。

Input.mousePosition;鼠标在键盘上的实时坐标。

12.Vector2

magnitude;返回向量的长度。根号下X的平方加Y的平方。

normalized;将长度不为一的向量在方向不变的情况下,将长度取一。不改变向量本身。 

sqrMagnitude;X的平方加Y的平方不开根号,一般用于较为节省性能的比较两个向量的长度

向量是结构体,如要修改,需整体修改。如

transform.position=new vector3(3,3,3);

如想要只修改物体的X坐标,直接调用transform.position.x是错误的。需:

Vector3 pos=transform.position;

pos.x=10;

transform.position=pos;

即可。

Vector2.Equals;判断两个向量是否相等。相等返回true,不相等返回flase.

Vector2.Normalize();将向量单位化,改变向量。

Vector2.Angle();用来取得两个向量的夹角。

Vector2.Distance(Vector2 a,Vector2 b);返回a,b两个点的距离。

Vector2.Dot()点乘。

Vector2.MoveTowards(Vector2 a,Vector2 b,float c);物体从a移动到b,c是速度。

13.Vector3

Vector3.MoveTowards();作用与Vector2的相同,用于移动。

Vector3.Normalize();单位化向量。

Vector3.Project(Vector3 a,Vector3 b);返回值为a在b身上的投影。

Vector3.Reflect(Vector3 a,Vector3 b);反射向量,a为入射光,为镜子的方向,返回值为出射光

Vector3.Slerp(Vector3 a,Vector3 b,Vector3 c);插值,由a转到b,c为速度。

14.Random随机数

Random.InitState();随机数的种子,相同的种子,随机数生成序列相同。

1.创建游戏物体f的三种方法
new GameObject();括号里可以添加想要创建的物体类型例如
new GameObject("Cube");创建出一个正方体
GameObject.Instantiate();
实例化Prefabs或实例化游戏物体
GameObject.CreatePrimitive();
创建原始图形如:.GameObject.CreatePrimitive(PrimitiveType.Cube);
2.通过代码给游戏物体添加组件
 private GameObject object;
object.AddComponent<Rigidbody>();
通过代码给游戏物体j添加脚本
object.AddComponent<脚本名>();
3.GameObject游戏物体的常用类
GameObject.activeInHierarchy 物体是否处于激活状态(包括自身及子物体)
4.UnityEngine下Object的静态方法
Object.Destroy:
Destroy(gameobject,time);
Object.DontDestroyOnLoad:
DontDestroyOnLoad(transform.gameObject);(在进行场景之间转换时不会被销毁,会被带到下一个场景中)
Object.FindObjectOfType:
Object   a =FindObjectOfType(typeof(组件名))
Rigidbody  a=FindObjectOfType<Rigidbody>();
只返回第一个被检测到含有此组件的物体。不查找未激活的游戏物体
Object.FindObjectsOfType:
Object   a =FindObjectsOfType(typeof(组件名))
Rigidbody a=FindObjectsOfType<Rigidbody>();
将检测到的所有的含有此组件的物体都存在数组中。不查找未激活的游戏物体
5.查找方法
Find(比较耗费性能)
FindGameObjectsWithTag返回所有是次标签的物体返回数组
FindWithTag只返回第一个检测到的物体。
6.游戏物体间消息的发送和接收
GameObject.BroadcastMessage();包括其自身及其子物体
GameObject.SendMessage(); 不包括子物体
GameObject.SendMessageUpwards();包括其自身及其父物体
7.得到组件的各种方法函数

GetComponent;只会得到在游戏物体身上的第一个检测到的组件

GetComponent;会得到物体上所有的组件

GetComponentInChildren;会得到其自身及其子物体身上第一个检测到的相应的组件

GetComponentInParent;会得到其自身及其父物体身上第一个检测到的相应的组件

GetComponentsInChildren;会得到其自身及其子物体身上所有检测到的相应的组件

GetComponentsInParent;会得到其自身及其父物体身上所有检测到的相应的组件

8.Public Functions

Invoke;

Public void Invoke(string methodName,float time );可延时调用方法

CancelInvoke;取消所有调用的方法(仅适用于当前脚本,不影响其他脚本中相同方法的调用)

InvokeRepeating;重复调用方法

IsInvoking;判断方法是否正在被调用

协程:

1.返回值是IEnumerator

2.返回参数时使用yield return null/0。

3协程方法的调用:使用StartCoroutine(需要调用的协程方法的名字);

4暂停yield return new WaitForSeconds(需要暂停的时间);

例如:

IEnumerator Method(){

内容;

yied return null;

}

StartCoroutine();开启协程

StopCoroutine();关闭协程

StopAllCoroutine();

9.与鼠标相关事件函数OnMouseXXX

OnMouseDown();当鼠标按下时触发

OnMouseUp();当鼠标抬起时触发

OnMouseDrag();当鼠标已经按下但没有抬起时触发

OnMouseEnter();当鼠标在游戏物体身上但没有按下鼠标时触发

ONMouseExit();当鼠标离开游戏物体时触发

OnMouseOver();当鼠标在游戏物体身上时无论是鼠标按下或没有按下只要鼠标在游戏物体身上就触发。

10.Mathf里面的方法

Mathf.PI 圆周率

Mathf.Deg2Rad 将度数转变为弧度

Mathf.Rad2Deg 将弧度转成度数

Mathf.Epsilon 无限小的数

Mathf.Infinity 无限大的数

Mathf.Abs 绝对值

Mathf.Ceil 向上取整

如Mathf.Ceil(10);结果为10.

Mathf.Ceil(10.2f);结果为11.

Mathf.Ceil(-10);结果为-10.

Mathf.Ceil(-10.2f);结果为-10.

Mathf.Floor();向下取整。

Mathf.Clamp(float value,float min,flaot max); valur为自己定义的数值。如果value小于min则将value改为min,如果value大于min且小于max则value为自身值,如果value大于max则将value改为max。

Mathf.ClosesPowerOfTwo(int value);取离value最近的2的多次方

如Mathf.ClosesPowerOfTwo(3);返回4

Mathf.ClosesPowerOfTwo(7);返回8

Mathf.DeltaAngle();返回角度之间的最小夹角。如721°-360°=361°,其返回1°。

Mathf.Exp(float power);代表e的power次方

Mathf.Max(float a,float b);比较两个数中的最大值(float可换为int)

Mathf.Max(float[] value);比较数组中的最大值(float可换为int)

Mathf.Min(float a,float b);比较两个数中的最小值(float可换为int)

Mathf.Min(float[] value)比较数组中的最小值(float可换为int

Mathf.Pow(float a,float b);a的b次方。

Mathf.Sqrt();开平方根。

Mathf.Lerp(float a,float b,float t);插值运算 

t为a到b之间的距离的比率,如t=0.5时,返回值为(a+b)*0.5,t为0时,返回值为a,t为1时返回值为b;

Mathf.LerpAngle();角度的差值运算

 Mathf.MoveToWards(float a,float b,float t);

a初始 值,b目标值,t从a到b每帧所移动的距离。

Mathf.PingPong(float a,float b);返回值在0到b之间0为最小值,b为最大值,返回值随着a的增大在0到b之间往返。

11.Input

GetTouch()屏幕触摸

Input.anyKeyDown();按下任何键都会触发,包括鼠标。

Input.mousePosition;鼠标在键盘上的实时坐标。

12.Vector2

magnitude;返回向量的长度。根号下X的平方加Y的平方。

normalized;将长度不为一的向量在方向不变的情况下,将长度取一。不改变向量本身。 

sqrMagnitude;X的平方加Y的平方不开根号,一般用于较为节省性能的比较两个向量的长度

向量是结构体,如要修改,需整体修改。如

transform.position=new vector3(3,3,3);

如想要只修改物体的X坐标,直接调用transform.position.x是错误的。需:

Vector3 pos=transform.position;

pos.x=10;

transform.position=pos;

即可。

Vector2.Equals;判断两个向量是否相等。相等返回true,不相等返回flase.

Vector2.Normalize();将向量单位化,改变向量。

Vector2.Angle();用来取得两个向量的夹角。

Vector2.Distance(Vector2 a,Vector2 b);返回a,b两个点的距离。

Vector2.Dot()点乘。

Vector2.MoveTowards(Vector2 a,Vector2 b,float c);物体从a移动到b,c是速度。

13.Vector3

Vector3.MoveTowards();作用与Vector2的相同,用于移动。

Vector3.Normalize();单位化向量。

Vector3.Project(Vector3 a,Vector3 b);返回值为a在b身上的投影。

Vector3.Reflect(Vector3 a,Vector3 b);反射向量,a为入射光,为镜子的方向,返回值为出射光

Vector3.Slerp(Vector3 a,Vector3 b,Vector3 c);插值,由a转到b,c为速度。

14.Random随机数

Random.InitState();随机数的种子,相同的种子,随机数生成序列相同。

Random.value();随机生成从0到1的值包括0和1。

Random.State();获取随机数的状态(种子)

Random.insideUnitCircle()*x在半径为x米的圆内随机生成。返回二维向量。

Random.insideUnitSphere();*x在半径为x的球体内生成为三位向量

15.四元数与欧拉角

当物体旋转时,当其绕x轴或z轴旋转时是绕其自身x轴和z轴旋转,当其绕y轴旋转时,是绕世界坐标的y轴旋转。

Quaternion.rotation;四元数。

Quaternion.eulerAngles;将一个四元数转变成欧拉角。也可直接设置物体的旋转。

 Quaternion.Euler将欧拉角转换为四元数。

Quaternion.LookRotation();将物体的朝向改为沿规定的向量,通常用来面向敌人。

Quaternion.Slerp();插值

Quaternion.Lerp();插值

16.Rigidbod刚体

Rigidbody.centerOfMass();取得物体的重心。

Rigidbody.position();可通过刚体修改物体的位置,且这种方法运行更快,推荐使用。

Rigidbody.MovePosition()控制物体平滑地运动(远距离使用)

Rigidbody.rotation();可通过刚体控制物体的旋转,且这种方法更快,推荐使用。

Rigidbody.MoveRotation();更加平滑的旋转,(长时间大角度连续旋转使用)。

Rigidbody.AddForce(a*b);施加力。a为想要物体运动大方向,为向量,b为施加在物体身上的力。

17.Camera

Camera.main();得到场景的第一个检测到的层为main Camera的相机

Camera.ScreenPointToRay();射线检测;

Camera.allCameras 返回场景中的所有摄像机以数组的形式

Camera.allCamerasCount 用来获取场景当中相机的数量

 

18.Application

 Application.datapath工程所在路径 

 Application.streamingAssetsPath可通过文件流来读取数据(不会被打包)

 Application.persistentDataPath

 Application.temporaryCachePath临时缓冲数据

  Application.identifier标识

 Application.companyName公司名

 Application.productName产品名(安装完成显示的名字)

 Application.installerName安装包的名字

 Application.installMode安装模式

 Application.isEditor用来判断是否在编辑器模式下运行。

Application.isFocused用来判断是否处于焦点

 Application.isMobilePlatform用来判断当前是否处于移动平台上运行

 Application.isPlaying用来判断是否正在运行(在编辑器模式下)

 Application.isWebPlayer

 Application.platform用来判断当前运行的环境

 Application.unityVersion用来得到开发应用的版本

 Application.runInBackground用来设置应用是否可以在后台运行

 Application.Quit();退出(编辑器模式下无效)

 Application.OpenURT();用来打开网站

 Application.CaptureScreeenshot("a");取得截图a为截图的名字

19.加载场景和SceneManager的其他方法

SceneManager.LoadScene();加载方法(1,通过场景标号;2,通过场景名字;)

SceneManager.LoadScene();异步加载,可以用来设置显示加载的进度条

SceneManager.CreateScene();创建新场景(在编辑器模式下)

SceneManager.GetActionsScene();获取当前场景

SceneManager.GetSceneAt();用来获取指定的场景

SceneManager.GetSceneAtBuildIndex();用来获取指定场景(通过场景标号index)

SceneManager.activeSceneChange();当场景发生变换时(加载新的场景时)触发

SceneManager.sceneLoaded();新场景加载完成时触发

SceneManager.sceneUnloaded();当场景由1转换到2 时,1会被卸载,当a被卸载完成时触发。

20.射线检测

Physics.Raycast();射线检测,检测所发生的射线是否与其他物体的碰撞器发生碰撞,如果发生返回true,没有发生返回false.

RaycastHit;有多种重载方式。如

RaycastHit b;

1.Physics.Raycast(a,out b);a为发射的射线,b为碰撞到的物体,可根据b返回碰撞到的物体的一些属性。

2.Physics.Raycast(a,b,LayerMask.GetMask("c"));a为发射的射线,b为射线的长度,c为想要检测到的物体的层,可设置多个层。

2D

Physics2D.Raycast();

Physics2D.RaycastAl();

21.UGUI事件监听

常见UGUI:

Button;按钮

Slider;滑动条

Dropdom;下拉菜单

Toggle;单选框

1.可通过拖拽添加监听事件

2.可通过代码添加 如:

GameObject.Getponent<Button>().onClick.AddListener();可通过此代码给Button添加监听事件。

3.通过实现接口:

IPointerDownHandler 鼠标按下。

IPointerClickHandler 鼠标点击(鼠标按下后抬起为一次点击)

IPointerUpHandler  鼠标抬起。

IpointerEnterHandler 鼠标移到物体上方。

IPointerExitHandler 鼠标移出

IBeginDragHandler 开始拖拽

IDragHandler 拖拽中

IEndDragHandler 结束拖拽

IDropHandler 拖拽开始与结束都在同一物体上时触发

IScrollHandler 滑轮滑动时触发

22.www

支持 http://    file://  ftp://(ftp://支持匿名下载及不需要登陆账号或一些权限的)

23.Touches

touches 用来获取当前触摸的数量,返回数组

GetTouch 用来获取触摸事件

24.CharacterController角色控制器(组件)

CharacterController.SimpleMove();简单移动

CharacterController.isGrounded 判断物体是否在地面上

CharacterController.move();

24.Mesh

25.Material材质类

a=GetComponent<MeshRenderer>().Material 获取材质的方法

26.Animator

Animator.speed 修改动画状态机的速度

SetBool();

SetFloat();

SetTarget();

SetTrigger();

System.DateTime.Now可以获取当前时间

[展开全文]

授课教师

SiKi学院老师

课程特色

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