unity中怎么定义walkspeed - 爱问答

(爱问答)

unity中怎么定义walkspeed

void Update () {

 

        Debug.Log("Horizontal value:" + Input.GetAxis("Horizontal"));

 

        Vector3 direction = Input.GetAxis("Horizontal") * transform.right +

            Input.GetAxis("Vertical") * transform.forward;

        transform.position = transform.position +

            walkSpeed * direction * Time.deltaTime;

 

    }


1、变量声明为public
public float speed = 1;
2、GetComponent返回的是Component类型,C#要求强类型(强制转换类型),不像js那样var变量直接使用
1、AutoRotation cmp1=(AutoRotation) GetComponent(typeof(AutoRotation));
cmp1.speed=10F;
2、AutoRotation cmp2=(AutoRotation) GetComponent("AutoRotation");
cmp2.speed+=10F;
3、AutoRotation cmp3= GetComponent<AutoRotation>();
print(cmp3.speed);
Unity3D语言参考在菜单:Help=>Scripting Reference
C#资料在网页版MSDN上http://msdn.microsoft.com/zh-cn/library/kx37x362.aspx
建议装visual studio 2010带离线版msdn,(我用这个)

下一篇:求解决的办法!

上一篇:求一段c语言程序

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?