unity study 2

阅读 85

2023-02-28

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

0 0 举报