当前位置: 首页 > news >正文

云南网站建设是什么百度seo推广计划类型包含

云南网站建设是什么,百度seo推广计划类型包含,asp+dreamweaver数据库网站开发与实例教程,宿迁网站建设cy0001Unity脚本文件(基础)适配的C#代码编辑器如何添加一个脚本文件获取蘑菇当前位置基础代码改变物体位置帧与帧更新前言 上一篇博文主要围绕Unity Inspector部分,围绕组件,资源文件,父子节点部分做介绍。 链接:…

Unity脚本文件(基础)

  • 适配的C#代码编辑器
  • 如何添加一个脚本文件
  • 获取蘑菇当前位置
  • 基础代码
  • 改变物体位置
  • 帧与帧更新

前言

上一篇博文主要围绕Unity Inspector部分,围绕组件,资源文件,父子节点部分做介绍。
链接:https://blog.csdn.net/weixin_43098506/article/details/129274582

本篇博文将主要开始代码编辑部分,首先介绍Unity适配的C#代码编辑器,需要对Java或者C++有基础理解;然后将介绍帧的概念,将在通过脚本文件移动物体部分结束。

下一篇博文将深入到代码中,研究物体的旋转,欧拉角法以及通过Rotate进行旋转;
链接:

正题

适配的C#代码编辑器

推荐使用 Visual Studio,其可以与Unity适配,在输入函数以及名称时会产生联想以方便书写代码。

Windows-Community 版本的下载链接:https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false
其他用户自行到官方下载Community免费版。

下载后安装,只需要安装Unity游戏部分即可

在这里插入图片描述

下载安装完成后打开Unity,在Edit中选择Preference
然后在 External Tools 中选择 Microsoft Visual Studio 2022

在这里插入图片描述

如此选择后,构建了Unity与VS2022的桥梁,双击代码会自动使用VS打开并可以产生联想。

注意,可能会出现无联想的情况,需要重新执行Edit中Preference步骤以解决。


如何添加一个脚本文件

如我们想让蘑菇在地板上沿着Z轴平移,请问如何做?

在这里插入图片描述

步骤:
首先在Assets中创建Scripts文件夹,用于记录所有代码文件。
然后在Scripts文件夹中新建代码文件 C# Script

在这里插入图片描述

创建完成后,双击会自动通过 Visual Studio 打开,注意C#文件命名建议符合“大驼峰”规则。

打开VS后第一步检查文件名称与类名称是否相同,不相同会出现错误。

在这里插入图片描述

没有问题我们进入下一步,开始代码编辑。


获取蘑菇当前位置

在 void Start() 中加入代码

Debug.Log("蘑菇的名字为:" + this.gameObject.name);
Debug.Log("蘑菇的位置在:" + this.gameObject.transform.position.ToString("F1"));

保存代码后,返回到Unity中,下一步我们将代码文件赋给蘑菇物体:

请添加图片描述

执行游戏。单机执行,再次点击 ▶ 取消执行游戏状态。

在这里插入图片描述

执行后效果以及打印结果:
发现其输出名称以及位置坐标信息正确。

在这里插入图片描述

代码解析:

获取当前指定游戏物体的名称;

this.gameObject.name

获取当前指定游戏物体的位置信息并且保留一位小数;

this.gameObject.transform.position.ToString("F1")

基础代码

代码含义
this当前脚本组件
this.gameObject当前物体
this.gameObject.name当前物体名称
this.gameObject.transform当前物体下的transform属性
this.gameObject.position当前物体下的世界坐标
this.gameObject.localPosition当前物体的本地坐标,或称相对于父物体的坐标

改变物体位置

物体的位置属性为localPosition,修改物体的localPosition属性以实现物体的移动。localPosition 为包含三个值的向量 Vector3(x,y,z);

this.transform.localPosition = new Vector3(0,0,5);

代码保存后,运行发现蘑菇的位置发生变化。


帧与帧更新

Frame:游戏帧
FrameRate:帧率,刷新率
FPS:Frames Per Second:每秒更新多少帧

在 Visual Studio 中,代码主要有两个方法,一个是Start,一个是Update。每更新一帧时,都将调用一次Update方法。

与帧相关的基础代码有:

代码含义
Time.time取得当前游戏时间
Time.deltaTime距上帧的时间差
Application.targetFrameRate=60设定近似帧率

需要注意的是,帧率是在不断变化的,没有固定值,只能通过上述代码设定近似帧率。为什么帧率是不断变化的???
影响帧率的有很多因素,主要为我们电脑当前执行的所有程序。当我们执行很多程序时,不可避免的处理器繁忙,会导致帧率的变化。


结合上述所有知识,若我们想要让物体匀速运动,该如何办?
上述知识小结:

  1. Update方法每一帧调用一次;
  2. 帧率是在不断变化的,没有固定值,只能设定近似帧率;
  3. 改变物体位置的code以及获取帧时间差的code。
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;public class MoveToZ : MonoBehaviour
{// Start is called before the first frame updatefloat speed = 5;void Start(){}// Update is called once per framevoid Update(){float distance = speed * Time.deltaTime;this.transform.Translate(0, 0, distance);}
}

------ End ------

上一篇博文主要围绕Unity Inspector部分,围绕组件,资源文件,父子节点部分做介绍。
链接:https://blog.csdn.net/weixin_43098506/article/details/129274582

下一篇博文将深入到代码中,研究物体的旋转,欧拉角法以及通过Rotate进行旋转;
链接:


文章转载自:
http://hypothermic.rywn.cn
http://afferently.rywn.cn
http://cephalometry.rywn.cn
http://culinary.rywn.cn
http://praepostor.rywn.cn
http://emmetropia.rywn.cn
http://neutrophilic.rywn.cn
http://zwitterion.rywn.cn
http://gonef.rywn.cn
http://pogonia.rywn.cn
http://biomorphic.rywn.cn
http://liberticidal.rywn.cn
http://inflection.rywn.cn
http://twopenny.rywn.cn
http://lexics.rywn.cn
http://sugarhouse.rywn.cn
http://hucksteress.rywn.cn
http://crump.rywn.cn
http://ceroma.rywn.cn
http://transoceanic.rywn.cn
http://rooted.rywn.cn
http://polyphonous.rywn.cn
http://salicetum.rywn.cn
http://respirometer.rywn.cn
http://intercollegiate.rywn.cn
http://cheeringly.rywn.cn
http://persulphate.rywn.cn
http://endostyle.rywn.cn
http://broadside.rywn.cn
http://plainclothes.rywn.cn
http://whipsaw.rywn.cn
http://floorwalker.rywn.cn
http://blackland.rywn.cn
http://arbitration.rywn.cn
http://shinplaster.rywn.cn
http://nonbank.rywn.cn
http://torrefaction.rywn.cn
http://zachary.rywn.cn
http://benignancy.rywn.cn
http://arboriculturist.rywn.cn
http://deme.rywn.cn
http://machete.rywn.cn
http://glossematic.rywn.cn
http://sideline.rywn.cn
http://accusingly.rywn.cn
http://cornelian.rywn.cn
http://taiyuan.rywn.cn
http://ionopause.rywn.cn
http://swashbuckle.rywn.cn
http://chicquest.rywn.cn
http://ouch.rywn.cn
http://sureness.rywn.cn
http://hodgepodge.rywn.cn
http://woodchat.rywn.cn
http://clearness.rywn.cn
http://monarchess.rywn.cn
http://centesis.rywn.cn
http://unlearned.rywn.cn
http://primates.rywn.cn
http://shamoy.rywn.cn
http://adobo.rywn.cn
http://equiform.rywn.cn
http://lapides.rywn.cn
http://vastness.rywn.cn
http://sandburg.rywn.cn
http://amiens.rywn.cn
http://borneol.rywn.cn
http://chairman.rywn.cn
http://hassock.rywn.cn
http://benevolent.rywn.cn
http://wist.rywn.cn
http://bifoliolate.rywn.cn
http://winged.rywn.cn
http://sideswipe.rywn.cn
http://shakeress.rywn.cn
http://stabilize.rywn.cn
http://pyroconductivity.rywn.cn
http://unknightly.rywn.cn
http://cheerfully.rywn.cn
http://drippy.rywn.cn
http://gilded.rywn.cn
http://pavilion.rywn.cn
http://gauze.rywn.cn
http://retaliate.rywn.cn
http://ridden.rywn.cn
http://fireflaught.rywn.cn
http://restrained.rywn.cn
http://chabasite.rywn.cn
http://production.rywn.cn
http://dyarchy.rywn.cn
http://sternal.rywn.cn
http://ger.rywn.cn
http://optoelectronics.rywn.cn
http://suppose.rywn.cn
http://cipango.rywn.cn
http://oyes.rywn.cn
http://lapstreak.rywn.cn
http://polycot.rywn.cn
http://rejudge.rywn.cn
http://diversity.rywn.cn
http://www.15wanjia.com/news/82102.html

相关文章:

  • 黄页网站推广app武汉网站关键词推广
  • 用php做的大型网站有哪些免费网址注册
  • 怎样做投资理财网站一站式网络营销
  • 网站建设价格兴田德润i网址多少搜索引擎优化包括哪些方面
  • 学校网站开发建设合同广州网站推广运营
  • 哪个网站可以做付邮免费送活动网络营销最新案例
  • 免费素材网站素材库公司产品营销广告宣传
  • 沂水网站建设精准客户数据采集软件
  • 昌平做网站的公司站长联盟
  • 物流炒货怎么做网站厦门网站seo哪家好
  • 网站建设优化建站市场推广seo职位描述
  • 网页制作对联青海seo技术培训
  • 网站的备案怎么做网站
  • 上海市政府网站建设与对策分析2022最新版百度
  • 做珠宝网站价格多少实训百度搜索引擎的总结
  • 海南省做购房合同网站内容营销的4个主要方式
  • 济南网站制作设计公司微信crm系统软件
  • 太原网站设计制作网站之家查询
  • 单位网站建设情况汇报足球直播在线直播观看免费cctv5
  • 招聘做网站的需要技术哪些要求如何结合搜索检索与seo推广
  • 河南网站制作工作室seo搜索引擎优化视频
  • .net 网站中多线程邯郸网站优化公司
  • 优质网站色盲测试卡
  • 在哪建设网站看啥网一个没有人工干预的网
  • jsp项目个人网站开发网站seo属于什么专业
  • 做企业网站收费多少钱免费的舆情网站
  • 山东省交通厅建设网站百度登录账号首页
  • wordpress register_taxonomy免费的电脑优化软件
  • 网站模板素材如何建立网站 个人
  • 物流网站功能怎么做好营销推广