0
点赞
收藏
分享

微信扫一扫

unity study 2

小桥流水2016 2023-02-28 阅读 83

使用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);

       }

   }


}

举报

相关推荐

0 条评论