首页 > 其他分享 >unity study 2

unity study 2

时间:2023-02-28 22:03:52浏览次数:35  
标签:frame void public horizontalmove unity rb using study

使用unity store寻找素材,编辑素材,并且用c#为我的人物添加了简单的移动动作,为场景和人物添加刚体,使其具有重力。

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class playcontroller : MonoBehaviour

{

   public Rigidbody2D rb;

   public float speed;

   // Start is called before the first frame update

   void Start()

   {

       

   }


   // Update is called once per frame

   void Update()

   {

       Movement();

   }

   void Movement()

   {

       float horizontalmove;

       horizontalmove=Input.GetAxis("Horizontal");

       if(horizontalmove!=0)

       {

           rb.velocity = new Vector2(horizontalmove * speed, rb.velocity.y);

       }

   }


}

标签:frame,void,public,horizontalmove,unity,rb,using,study
From: https://blog.51cto.com/u_15918782/6091825

相关文章

  • unity 阿拉伯数字转中文汉字
    直接调用即可代码如下: usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.Text;usingUnityEngine;publicclassToolS......
  • Unity URP Shader 基础光照
    函数GetMainLight()返回一个数据结构LightstructLight{half3direction;//颜色&强度half3color;//方向halfdistanceAttenuation;//距......
  • [Unity/C#]委托+协程,依次启动多播委托里协程的方法
    1//委托的定义2publicdelegateIEnumeratorActiveDuringTurn(Player[]otherplayers);34publiceventActiveDuringTurnUEvent;567//依次启动协程......
  • 有关Unity中Text控件文本不能换行或换行无效的解决方案
    解决方案如下: 这里简单说明一下:@标识符用于禁止把后面的“\n”转化掉,也就是使用完“\n”的转移效果就会保留,自然就能换行了。@似乎只能加在""之......
  • Unity获取所有场景的名字
    ///<summary>获取所有场景名字</summary>privatestring[]getAllSceneName(){intcount=SceneManager.sceneCountInBuildSettings;string[]sc......
  • 【unity】基于Playable的自定义动画系统
    前言开发时逐渐对蜘蛛网动画系统中重复性的工作感到厌烦,而且当动画一多起来,即使蜘蛛网分了层,我仍然连看都不想看。遂寻求解决方案。蜘蛛网那一套系统不支持在运行时创建......
  • Unity 性能优化之DynamicBone
    DynmaicBone最新版本使用了多线程,30人同屏情况下消耗为6ms左右,如下图:这个消耗依旧挺大,会使50帧的游戏降10帧左右。 使用jobsystem+burst优化后的消耗为0.05ms,......
  • Unity 进去区域时显示模型,离开区域时候隐藏模型
    1.在“MainCamera”下面创建一个Cube,调整大小,并将其Tag指定为“Player”(如下图所示)。 2.新建一个脚本,命名为“Tourcamera”,用来控制相机的移动(代码如下),并将其挂......
  • win11_安装VScommunity|CUDA|pytorch
    注意:安装cuda过程中,有一步会检查是否安装了VisualStudio,所以本文中先安装VisualStudio,再安装cuda。参考:https://blog.csdn.net/weixin_44019018/article/details/122052......
  • unity 单元测试
    unity单元测试Created:February23,202311:11PMTags:C语言,stm32,单元测试概述为了方便在stm32上进行单元测试,需要在项目中导入unity框架以便于对项目的单元测......