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

协程暂停3秒后继续执行

IEnumerator changeColor()

{

print("hha");

yield return new waitforseconds(3);

print("hahah");

}

 

利用协程操作物体颜色渐变

IEnumerator fade()

{

for(float i=0;i<=1;i=i+0.1f)

{

cube.GetComponent<MeshRenderer>().material.color=new color(i,i,i);

yield return new waitforseconds(0.1f); 

}

}

Color.Lerp 插值

 

static function Lerp (a : Color, b : Color, t : float) : Color

Description描述

Interpolates between colors a and b by t.

通过t在颜色a和b之间插值。

/t/ is clamped between 0 and 1. When t is 0 returns a. When t is 1 returns b.

"t"是夹在0到1之间的值。当t是0时返回颜色a。当t是1时返回颜色b。

[展开全文]
统帅 · 2019-02-19 · 该任务已被删除 0

协程定义方法:

IEnumerator changeColor()

{

print("hello");

yield return null;

}

协程调用方法:

StartCoroutine(changeColor());

协程与主线程同时执行,并行

[展开全文]
统帅 · 2019-02-19 · 该任务已被删除 0

sendmessage其实就是调用某个gameobject里script组件里的某个方法,message就是方法名

[展开全文]
统帅 · 2019-02-19 · 该任务已被删除 0

if( Input.anyKeyDown){

    print("any key down");

}

print(Input.mousePosition);

左下角为原点。

 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

Input.GetButtonDown("Horizontal")

按下AD键,触发是有用的,前提是输入法为英文输入法状态

 

cube.Translate(Vecctor3.right * Time.deltaTime * Input.GetAxis("Horizontal"));

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

Input.GetMouseButton(0) 鼠标左击

Input.GetMouseButton(1) 鼠标右击

Input.GetMouseButton(2) 鼠标中间按下

 

GetMouseButtonDown()

GetMouseButtonU

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

Input.GetKeyDown()

Input.GetKeyUp()

Input.GetKey()

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

ime 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

PingPong 

cube.position = new Vector3(Mathf.PingPong(Time.time*speed,10),0,0);

 

5+Mathf.PingPong(Time.time*speed,5)

5-10之间

 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

MoveToWards 做匀速运动

void Update(){

float x = cube.position.x;

float newX = Mathf.MoveTowards(x,10,0.1f);

cube.position = new Vector3(newX,0,0);

}

0.1f 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

Lerp 插值运算 (做动画效果)

先快后慢

 

void Update(){

    float x = cube.position.x;

    float newX = Mathf.Lerp(x,10,0.1f);

    cube.position = new Vector3(newX,0,0);

}

0.1f 替换成Time.deltaTime

 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

ClosePowerOfTwo 离2的次方最近的数

Floor 向下取整

FloorToInt 向下取整

Max 取得最大值

Min 取得最小值

Pow(f,p)取得 f 的 p 次方

Sqrt 取得参数的平方根

 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

Abs 取绝对值

Ceil 向上取整,返回值为float类型

CeilToInt 向上取整,返回值为Int类型

Clamp 把一个值限定在一个范围之内,把一个值夹紧

Clamp01 把一个值限定在0-1

 

void TakeDamage(){

    hp-=9;

    hp = Mathf.Clamp(hp, 0, 100);

}

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

Mathf

 Deg2Rad                0.01745329

 Rad2Deg                57.29578

 Infinity                    Infinity

 NegativeInfinity     -Infinity

 PI                            3.141593

 Epsilon                    1.401298E-45

 

 

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

 

void OnMouseDown(){}

void OnMouseUp(){}

void OnMouseDrag(){}

 

void OnMouseEnter(){}

void OnMouseExit(){}

void OnMouseOver(){}

 

void OnMouseUpAsButton(){}

 

 

 

if是Trigger:

①Trigger

②Edit---Project Settings---Physics:Queries Hit Triggers 打勾

[展开全文]
遗失的星空 · 2019-02-12 · 该任务已被删除 0

BroadacatMessage

[展开全文]
Cckp · 2019-02-11 · 该任务已被删除 0

GameObject.CreatePrimitive(PrimtiveType.Plane);

[展开全文]
conedge · 2019-02-09 · 该任务已被删除 0

Unity版本变化对于场景的影响:

Application.LoadLevel("Level2");
//加载场景的方法变更为
SceneManeger.LoadScene("Scene2");

需要在开始处声明

using UnityEngine.SceneManagement;

 

[展开全文]
漠Paranoid · 2019-02-05 · 该任务已被删除 0

Unity版本上的一些变化:

1.物体的组件不能直接访问了,需要用GetComponent<>来进行访问

(从节约性能的角度考虑,寻找组件是耗费性能的,不要把GetComponent放在Update方法里,可以现在外面声明了变量,在从Start方法里获取)

 

[展开全文]
漠Paranoid · 2019-02-05 · 该任务已被删除 0

颜色渐变的效果

Material材质:

mat = GetComponent<MeshRenderer>().material;

从MeshRenderer组件身上获取材质

颜色渐变API:Lerp

(当前颜色,渐变颜色,变化速度)

[展开全文]
漠Paranoid · 2019-02-05 · 该任务已被删除 0

授课教师

问问题加入A计划,有专门负责答疑的老师哦!!!

课程特色

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