c# - 当我的角色移动到不同的方向时,我的 Unity 2D 播放器控制器脚本不会让我的角色翻转
问题描述
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
public float jumpForce;
private float moveInput;
private Rigidbody2D rb;
private bool facingRight = true;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
}
void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0)
{
Flip();
}
else if(facingRight == true && moveInput < 0)
{
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
我制作了 ac# 2D 播放器控制器脚本以统一使用,但是当我点击播放时,我的播放器在移动不同方向时不会翻转并面对不同的方向。谁能发现我的脚本有什么问题?
解决方案
没关系。只是一个愚蠢的错误。我将一个过时和更新的脚本组件放入我的播放器中。是的,我知道我很愚蠢。
推荐阅读
- reactjs - 在反应中使用上下文
- java - 在java中用不同的参数类型覆盖子类中的方法
- javascript - 基于多种因素删除特定产品
- dart - 检查 if 条件中使用的 bool 变量的可空性的简写
- javascript - 非常简单的 Javascript - 试图 console.log 一个对象数组 - 不工作?
- ios - 这叫什么,我该如何删除它?
- java - android活动运行时,互联网关闭警报在互联网关闭后没有出现
- c - 如何使用结构对象中的值在 C 中对字符串日期进行排序
- python - 计算从标准输入 Python 读取图形的复杂度
- kubernetes - Ocelot api gateway - kubernetes - error: "namespace:serviceservice:managementservice Unable to use , it is invalid. Address must contain only host ...."