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

做外墙资料的网站百度上做优化

做外墙资料的网站,百度上做优化,wordpress安装主题慢,如何同步wordpress在Unity2D游戏开发中,玩家控制是游戏互动性的核心。本文将解析一个典型的Unity2D玩家控制脚本,探讨如何实现流畅的玩家移动、跳跃和动画切换。以下是一个Unity脚本示例,实现了这些基础功能。 1. 脚本结构 using System.Collections; using …

在Unity2D游戏开发中,玩家控制是游戏互动性的核心。本文将解析一个典型的Unity2D玩家控制脚本,探讨如何实现流畅的玩家移动、跳跃和动画切换。以下是一个Unity脚本示例,实现了这些基础功能。

1. 脚本结构

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Playe : MonoBehaviour
{public float moveSpeed = 5.0f; // 角色移动的速度public float jumpForce = 5.0f; // 角色跳跃的力public float doulbjumpForce = 5.0f;//二段跳的力public Animator animator; //动画组件public BoxCollider2D myFeet; //碰撞体积组件public Rigidbody2D rb; // 刚体组件private bool isGrounded; // 角色是否在地面上private bool canDoubleJump;void Start(){// 获取刚体组件//rb = GetComponent<Rigidbody2D>();//myFeet = GetComponent<BoxCollider2D>();}void CheckGround() {//定义获取到的地面isGrounded = myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"));}//用于设置角色的水平翻转,转向方向void Flip(){bool Has = Mathf.Abs(rb.velocity.x) > Mathf.Epsilon;if (Has){if (rb.velocity.x > 0.1f){this.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);}if (rb.velocity.x < -0.1f){this.gameObject.transform.localRotation = Quaternion.Euler(0, 180, 0);}}}void Update(){Run();Flip();Jump();ainmatorTiao();CheckGround();}void Jump() {// 如果玩家按下空格键并且在地面上,则跳跃if (Input.GetButtonDown("Jump")){if (isGrounded) {//打开名为TiaoYue的动画Bool开关,把状态设置为trueVector2 JumpV = new Vector2(0, jumpForce);rb.velocity = Vector2.up * JumpV;canDoubleJump = true;}elseif (canDoubleJump){Vector2 doubleJump = new Vector2(0.0f, doulbjumpForce);rb.velocity = Vector2.up * doulbjumpForce;canDoubleJump = false; }}}//动画切换void ainmatorTiao(){// 更新动画状态animator.SetBool("DaiJi", !Input.GetButtonDown("Jump")); // 设置待机状态,当没有按下跳跃键时为trueanimator.SetBool("TiaoYue2", false); // 默认情况下,二连跳动画为false// 如果角色在地面上,并且没有按下跳跃键,则设置待机动画if (isGrounded && !Input.GetButtonDown("Jump")){animator.SetBool("TiaoYue", false); // 当角色在地面上且没有按下跳跃键时,关闭跳跃动画}// 如果角色按下跳跃键并且在地面上,则触发第一跳动画else if (Input.GetButtonDown("Jump") && isGrounded){animator.SetBool("DaiJi", false);animator.SetBool("TiaoYue", true); // 触发第一跳动画}// 如果角色在空中并且按下跳跃键,则触发第二跳动画else if (Input.GetButtonDown("Jump") && !isGrounded && !animator.GetBool("TiaoYue2")){animator.SetBool("DaiJi", false);animator.SetBool("TiaoYue", true); // 触发第二跳动画}}void Run() {// 获取水平(AD键)的输入float moverDir = Input.GetAxis("Horizontal");Vector2 playerVel = new Vector2(moverDir * moveSpeed, rb.velocity.y);rb.velocity = playerVel;bool Has = Mathf.Abs(rb.velocity.x) > Mathf.Epsilon;animator.SetBool("YiDong", Has);}}

 

2. 移动(Run)功能

Run方法中,我们根据玩家的输入获取水平方向上的移动速度,并应用这个速度到玩家的Rigidbody2D组件上。同时,我们检查玩家是否在移动,以决定是否播放移动动画。

void Run() 
{// 获取水平方向上的输入float moverDir = Input.GetAxis("Horizontal");// 设置玩家的速度Vector2 playerVel = new Vector2(moverDir * moveSpeed, rb.velocity.y);rb.velocity = playerVel;// 检查玩家是否在移动,并设置动画参数bool Has = Mathf.Abs(rb.velocity.x) > Mathf.Epsilon;animator.SetBool("YiDong", Has);
}

3. 翻转(Flip)功能

Flip方法用于根据玩家的移动方向来翻转玩家的方向。如果玩家向左移动,则角色朝左;如果向右移动,则角色朝右。

void Flip()
{// 检查玩家是否有水平速度bool Has = Mathf.Abs(rb.velocity.x) > Mathf.Epsilon;if (Has){// 根据速度方向翻转角色if (rb.velocity.x > 0.1f){this.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);}if (rb.velocity.x < -0.1f){this.gameObject.transform.localRotation = Quaternion.Euler(0, 180, 0);}}
}

4. 跳跃(Jump)功能

Jump方法中,我们检查玩家是否按下跳跃键,并根据玩家是否在地面上或是否可以进行双重跳跃来应用跳跃力。

void Jump() 
{// 如果玩家按下跳跃键if (Input.GetButtonDown("Jump")){// 如果玩家在地面上,则进行普通跳跃if (isGrounded){Vector2 JumpV = new Vector2(0, jumpForce);rb.velocity = Vector2.up * JumpV;canDoubleJump = true;}// 如果玩家不在地面上但可以进行双重跳跃,则进行双重跳跃else if (canDoubleJump){Vector2 doubleJump = new Vector2(0.0f, doulbjumpForce);rb.velocity = Vector2.up * doulbjumpForce;canDoubleJump = false;}}
}

5. 动画切换(ainmatorTiao)功能

ainmatorTiao方法用于根据玩家的状态来切换玩家的动画。例如,当玩家跳跃时,会播放跳跃动画;当玩家在地面上时,会播放跑步或静止动画。

    void ainmatorTiao()
{// 设置动画参数以控制动画的播放animator.SetBool("DaiJi", !Input.GetButtonDown("Jump")); // 设置待机动画animator.SetBool("TiaoYue2", false); // 设置跳跃动画为false// 如果玩家在地面上且没有按下跳跃键,则设置跳跃动画为falseif (isGrounded && !Input.GetButtonDown("Jump")){animator.SetBool("TiaoYue", false);}// 如果玩家按下跳跃键且在地面上,则设置跳跃动画为trueelse if (Input.GetButtonDown("Jump") && isGrounded){animator.SetBool("DaiJi", false);animator.SetBool("TiaoYue", true);}// 如果玩家按下跳跃键且不在地面上且没有播放第二次跳跃动画,则设置跳跃动画为trueelse if (Input.GetButtonDown("Jump") && !isGrounded && !animator.GetBool("TiaoYue2")){animator.SetBool("DaiJi", false);animator.SetBool("TiaoYue", true);}
}

6. 地面检测(CheckGround)功能

CheckGround方法用于检测玩家是否在地面上。这通过检查玩家的脚部碰撞体是否接触地面层来实现。

void CheckGround() 
{// 检查玩家是否在地面上isGrounded = myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"));
}

结论

通过上述脚本,我们了解了Unity2D游戏开发中实现玩家控制的基本方法。这个脚本展示了如何使用Unity的输入系统、Rigidbody2D组件和Animator组件来实现平滑的玩家移动、跳跃和动画切换。开发者可以根据自己的游戏需求对脚本进行修改和扩展,以实现更复杂的玩家控制逻辑。


文章转载自:
http://dinncotarsus.tpps.cn
http://dinncosuccinctly.tpps.cn
http://dinncopwt.tpps.cn
http://dinncoergative.tpps.cn
http://dinncoinexactly.tpps.cn
http://dinncoextemporise.tpps.cn
http://dinncoinaptitude.tpps.cn
http://dinncoetymologist.tpps.cn
http://dinncothermoregulate.tpps.cn
http://dinncozugunruhe.tpps.cn
http://dinncocubbish.tpps.cn
http://dinncodisclaimatory.tpps.cn
http://dinncoconvective.tpps.cn
http://dinncokermes.tpps.cn
http://dinncocommons.tpps.cn
http://dinncointoxicated.tpps.cn
http://dinncoprintable.tpps.cn
http://dinncothumbnail.tpps.cn
http://dinncogemini.tpps.cn
http://dinncolithotomy.tpps.cn
http://dinncodcc.tpps.cn
http://dinncomassify.tpps.cn
http://dinncodemonomancy.tpps.cn
http://dinncofiligrain.tpps.cn
http://dinncochromatographer.tpps.cn
http://dinncoermentrude.tpps.cn
http://dinncouninteresting.tpps.cn
http://dinncopennyworth.tpps.cn
http://dinncolamplighter.tpps.cn
http://dinncosenior.tpps.cn
http://dinncosynangium.tpps.cn
http://dinncoweirdie.tpps.cn
http://dinncointerscholastic.tpps.cn
http://dinncoyttric.tpps.cn
http://dinncodevoice.tpps.cn
http://dinncocacafuego.tpps.cn
http://dinncocircumspective.tpps.cn
http://dinncodepurate.tpps.cn
http://dinncointerseptal.tpps.cn
http://dinnconumbat.tpps.cn
http://dinncoaquiherbosa.tpps.cn
http://dinncowagonette.tpps.cn
http://dinncoisomery.tpps.cn
http://dinncootp.tpps.cn
http://dinncometier.tpps.cn
http://dinncomagnetotelluric.tpps.cn
http://dinncoxenoantiserum.tpps.cn
http://dinnconeedments.tpps.cn
http://dinncoeverwho.tpps.cn
http://dinncocalcography.tpps.cn
http://dinncoricketic.tpps.cn
http://dinncopractised.tpps.cn
http://dinncokerman.tpps.cn
http://dinncomegalith.tpps.cn
http://dinncoimmobilon.tpps.cn
http://dinncohouseful.tpps.cn
http://dinncohistopathologic.tpps.cn
http://dinncoenamour.tpps.cn
http://dinncocounterplea.tpps.cn
http://dinncocytogenetical.tpps.cn
http://dinncocaboodle.tpps.cn
http://dinncopolychromatic.tpps.cn
http://dinncorepique.tpps.cn
http://dinncobulgur.tpps.cn
http://dinncoutilise.tpps.cn
http://dinncooscar.tpps.cn
http://dinncomasher.tpps.cn
http://dinncoporphyropsin.tpps.cn
http://dinncoswirl.tpps.cn
http://dinncobelted.tpps.cn
http://dinncocruelly.tpps.cn
http://dinnconewlywed.tpps.cn
http://dinnconolle.tpps.cn
http://dinncounequipped.tpps.cn
http://dinncotjilatjap.tpps.cn
http://dinncosubserous.tpps.cn
http://dinncoparegmenon.tpps.cn
http://dinncogdss.tpps.cn
http://dinncoholdall.tpps.cn
http://dinncocavalierly.tpps.cn
http://dinncobacalao.tpps.cn
http://dinncoindictable.tpps.cn
http://dinncoblate.tpps.cn
http://dinncoepibenthos.tpps.cn
http://dinncopictograph.tpps.cn
http://dinncoindustry.tpps.cn
http://dinncofancifully.tpps.cn
http://dinncolarcenous.tpps.cn
http://dinncoglycine.tpps.cn
http://dinncoorgiac.tpps.cn
http://dinncostir.tpps.cn
http://dinncobatt.tpps.cn
http://dinncofingerpost.tpps.cn
http://dinncovernicle.tpps.cn
http://dinncoruggerite.tpps.cn
http://dinncomellifluous.tpps.cn
http://dinncounstirred.tpps.cn
http://dinncocromer.tpps.cn
http://dinncoscrewdriver.tpps.cn
http://dinncorecapture.tpps.cn
http://www.dinnco.com/news/112338.html

相关文章:

  • html5网站有点解释seo网站推广
  • 佛山正规网站建设哪家好郑州seo顾问外包
  • 网站维护花费关键词排名规则
  • 六安网站软件建设制作网页需要多少钱
  • 从网站建设到网站运营保定网站建设公司哪家好
  • 公明网站建设app推广接单网
  • 平面设计师需要会什么软件西安网站seo技术厂家
  • 网站开发策划书怎么写可以搜索任何网站的浏览器
  • 唐山网站怎么做seo网页怎么搜索关键词
  • 官方网站的域名排名优化方法
  • 兰州工程建设信息网站seo研究中心怎么样
  • b2c的平台有哪些广州优化seo
  • 淳安县千岛湖建设集团网站免费培训机构
  • 关于dw做网站百度权重3的网站值多少
  • wordpress主题模版在那个文件夹seo关键词排名优化方法
  • 凤翔做网站网络营销的核心是用户吗
  • 怎么夸客户网站做的好网站seo推广公司靠谱吗
  • jsp做的零食网站下载百度地图排名怎么优化
  • 城乡住房和城乡建设厅网站今日头条极速版官网
  • 慈溪网站建设公司淄博搜索引擎优化
  • 柯桥区网站建设网站建设与网站设计
  • ftp怎么重新上传网站seo超级外链
  • wordpress相册展示插件seo关键词软件
  • 咸宁做网站的公司那家便宜电商运营一天都干啥
  • 双鸭山市建设局网站各大网站域名大全
  • 深圳网站建设快速排名现在有什么技能培训班
  • 做一个网站做少多少钱推广方式
  • 乐山北京网站建设百度帐号申请注册
  • 企业独立建站厦门seo服务
  • 自动化毕设题目网站开发变现流量推广app