6213人加入学习
(22人评价)
Unity常用API方法与类详细讲解 - 知识理论篇

制作完成于2022年3月8日,基于Unity2020.3

价格 免费

//平滑阻尼

.SmoothDamp(girsTrans.position,targetTrans.position,ref currentVelocity,1) 平滑时间为1ref一定要带,平滑速度

[展开全文]

Input.GetButton("Fire1)  //返回一个bool值,鼠标按下或不松手都会触发

[展开全文]

静态方法:GameObject.Instantiate;

GameObject.CreatePrimitive;

GameObject.SetActive(true);激活  false为失活

标签

gameobject.tag;物理检测或者渲染

层级

gameobject.layer;物理检测或者渲染

 

[展开全文]

using System.Collections; using System.Collections.Generic; using UnityEngine; public class No10_Animator : MonoBehaviour { public Animator animator; void Start() { animator.Play("Run"); animator.speed = 5; animator.speed = 0.5f; animator.SetFloat("Speed", 1); animator.SetBool("Dead",false); animator.SetInteger("HP", 100); print("当前速度参数是:" + animator.GetFloat("Speed")); } // Update is called once per frame void Update() { //按键切换动画状态 if (Input.GetKeyDown(KeyCode.W)) { animator.CrossFade("Walk", 1f); } } }

[展开全文]

1.向下发送消息:

BroadcastMessage("GetMsg");

2.向上发送消息:

SendMessageUpwards("GetMsg");

[展开全文]

 

激活的另一种表达形式:Debug.Log("当前游戏物体的状态是:"+gameobject.activeInHierarchy);

Debug.Log("当前游戏物体的状态是:"+gameobject.activeSelf);

游戏物体的查找

a.通过名称查找游戏物体

1.有引用

对自己 用this.gameobject;

对其他游戏物体:Debug.Log("gris游戏物体的状态是:"+grisGo.activeSelf);

2.无直接引用

对其他游戏物体:通过名称查找GameObject mainCameraGo//用一个容器把外部的游戏物体给存起来= GameObject.Find("Main Camera");  Debug.Log("mainCamera游戏物体的标签是:"+mainCameraGo.tag);

 

[展开全文]

通过标签与类型查找游戏物体//游戏物体必须是激活状态

GameObject mainCameraGo = GameObject.FindGameObjectwithTag("MainCamera");

Debug.Log("mainCamera游戏物体的标签是:"+mainCameraGo.tag);

通过类型查找

No2_EvenFunction no2_EventFunction=Gameobject.FindofType<No2_EvenFunction>();

Debug.Log("no2_EventFunction游戏物体的名字是:"+No2_EventFunction.name);

多个youxiw数查找与获取

[展开全文]

定义一个方法框架

CAlculate()  计算

Add() 加法

Subtract()  减法

[展开全文]

1.animator.Play("Run");成员方法,播放动画状态。

2.animator.speed;成员变量,动画播放速度。

3.animator..SetFloat();成员方法,

 

 

[展开全文]

animator.CrossFadeInFixedTime():成员方法,

[展开全文]