问题描述
我试图在按下箭头键时翻转精灵,但是它们以某种方式从相机的末端中消失了。在我看来,整个摄像头都是翻转的,而不是精灵。解决这个问题的正确方法是什么?
当用户按下向左/向右箭头键时,我试图翻转。下面是我的代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed;
public float input;
Rigidbody2D rb;
Animator anim;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
private void Update ()
{
if (input != 0) {
print("is running");
anim.SetBool("isRunning",true);
} else {
print("is not running");
anim.SetBool("isRunning",false);
}
if (input > 0) {
transform.eulerAngles = new Vector3(0,0);
}else if (input < 0){
transform.eulerAngles = new Vector3(0,180,0);
}
}
// Update is called once per frame
void FixedUpdate()
{
input = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(input * speed,rb.velocity.y);
}
}
感谢您的帮助。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)