Unity2D入门1 简单角色移动与动画 基础

本文档介绍了Unity2D中如何实现角色的简单移动和跳跃功能。通过利用getAxisRaw和fixedUpdate确保角色在不同帧率下的移动速度一致,使用Time.fixedDeltaTime进行精确控制。同时,通过修改动画状态Bool来切换角色动画,实现跑步和跳跃的视觉效果。跳跃部分详细讲解了如何判断和处理跳跃、下落和落地的动画状态变化。
摘要由CSDN通过智能技术生成

学习内容来自 B站up : M_Studio
文中使用图片素材来自unity素材库 2D- Sunnyland

简单角色移动完整代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControl : MonoBehaviour
{
   
    public Rigidbody2D rb;
    public Animator Anim;
    public Collider2D coll;
    public float speed;
    public float jumphigh;
    public LayerMask Ground;

    // Start is called before the first frame update
    void Start()
    {
   
        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
   
        Playermove();
        SwitchAnim();
    }

    void Playermove() 
    {
   
        float Horizontalmove;
        float Facedirection;
        Horizontalmove = Input.GetAxis("Horizontal"); 
        Facedirection = Input.GetAxisRaw("Horizontal");

        // 移动
        if (Facedirection != 0)
        {
   
            transform.localScale = new Vector3(Facedirection, 1, 1);
        }
        if (Horizontalmove 
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值