[Unity学习随笔3/15]quard的trigger属性,SmoothDamp函数
BUG记录:
NullReferenceException: Object reference not set to an instance of an object
可能是脚本中的对象未绑定(或者对象改名后忘记重新绑定)
Quard中的该属性: 用来虚化/实化空间及判断空间是否被入侵, 可拓写相应的触发函数
private void OntriggerEnter( ){ } | 进入该空间 |
private void OntriggerStay( ){ } | 在该区域停留 |
private void OntriggerExit( ){ } | 离开该区域 |
getaxis的horizal和vertical只适用于键盘,对多设备输入的支持不灵活
GetAixs对设备的支持可以在edit -> projectsetting -> inputmanager设定
SmoothDamp可以使按键变动的信号过渡更加平缓自然
public class PlayerInput : MonoBehaviour
{
public string keyUp = "w";
public string keyDown = "s";
public string keyLeft = "a";
public string keyRight = "d";
public float Dup;
public float Dright;
public bool inputEnabled = true;
private float targetDup;
private float targetDright;
private float velocityDup;
private float velocityDright;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
targetDup = (Input.GetKey(keyUp) ? 1.0f : 0) - (Input.GetKey(keyDown) ? 1.0f : 0);
targetDright = (Input.GetKey(keyRight) ? 1.0f : 0) - (Input.GetKey(keyLeft) ? 1.0f : 0);
if (inputEnabled == false)
{
targetDup = 0;
targetDright = 0;
}
Dup = Mathf.SmoothDamp(Dup, targetDup, ref velocityDup, 0.1f);
Dright = Mathf.SmoothDamp(Dright, targetDright, ref velocityDright, 0.1f);
}
}
[专栏作家]Unity中Lerp与SmoothDamp函数使用误区浅析 (sohu.com)https://www.sohu.com/a/211459755_667928
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/16010845.html
分类:
Unity
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)