using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playing : MonoBehaviour
{
public float runSpeed;
private Rigidbody2D myRigidbody;
private Animator myAnim;
// Start is called before the first frame update
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
myAnim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
run();
}
void run()
{
float movDir = Input.GetAxis("Horizontal");
Vector2 playerVel = new Vector2(movDir * runSpeed, myRigidbody.velocity.y);
myRigidbody.velocity = playerVel;
bool playerHasX = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
myAnim.SetBool("run", playerHasX);
}
}
上述代码实现了角色的速度设置以及移动的开始与解释之间的相互关系
角色可以在方块上进行移动的操作,如果想继续了解游戏的发展那么就点个关注吧,未来还会添加npc以及故事情节以及更多角色的动作以及操作。