Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity 2D-跳跃动画重置_C#_Unity3d_2d - Fatal编程技术网

C# Unity 2D-跳跃动画重置

C# Unity 2D-跳跃动画重置,c#,unity3d,2d,C#,Unity3d,2d,我对Unity world(2D)是新手,遇到了一些问题 我有一个脚本,我想在其中跳转。当我跳跃时,跳跃动画非常快。您只能在动画师中看到它 我还有另外两个动画(空闲、运行)可以正常工作 你能帮帮我吗( 公共类玩家:单行为 { 私有刚体2d刚性; [序列化字段] 专用浮子跳线力=5.0f; 私人跳伞; [序列化字段] 私人浮动速度=5.0f; 私人游戏机动画游戏机; 私人精灵玩家Prite; //在第一帧更新之前调用Start void Start() { ... } //每帧调用一次更新 无效更

我对Unity world(2D)是新手,遇到了一些问题

我有一个脚本,我想在其中跳转。当我跳跃时,跳跃动画非常快。您只能在动画师中看到它

我还有另外两个动画(空闲、运行)可以正常工作

你能帮帮我吗(

公共类玩家:单行为
{
私有刚体2d刚性;
[序列化字段]
专用浮子跳线力=5.0f;
私人跳伞;
[序列化字段]
私人浮动速度=5.0f;
私人游戏机动画游戏机;
私人精灵玩家Prite;
//在第一帧更新之前调用Start
void Start()
{
...
}
//每帧调用一次更新
无效更新()
{
运动();
}
空位移动()
{
float move=Input.GetAxisRaw(“水平”);
翻转(移动);
如果(isground())
{            
playerAnim.Jump(假);
}
if(Input.GetKeyDown(KeyCode.Space)&&isground()==true)
{
刚性.velocity=新矢量2(刚性.velocity.x,跳跃力);
启动例程(ResetJumpNeededRoutine());
playerAnim.Jump(真);
}        
刚性.velocity=新矢量2(移动*速度,刚性.velocity.y);
playerAnim.Move(移动);
}
无效翻转(浮动移动)
{
...
}
bool-IsGrounded()
{

RaycastHit2D hitInfo=Physics2D.Raycast(transform.position,Vector2.down,0.3f,1问题出在你的代码中,就在按下空格后,resetjump变为false,isground()变为true,因此jump anim变为false。所以我坚持的是设置trigger而不是设置playerAnim.jump使用playerAnim.SetTrigger(“jump”)


关于动画触发器的研究我们使用触发器播放动画,如射击和跳跃,因为这些动画为真,然后在下一个瞬间为假。

我建议您在查看脚本之前查看动画师和动画。检查是否:a)动画师速度(默认为1)b)存在“已退出时间”在“animator”状态下,您可以尝试取消选中它,这样动画就可以在更改状态之前结束。c)对动画使用触发器而不是布尔值(将默认值设置为空闲,并在跳转时触发动画)。看来你的代码没有问题,所以我想这可能与动画师或动画有关。非常感谢你的回答。我再次检查了你提到的要点。a.速度=1;我已更改并测试,没有更改b.退出时间=禁用,我也尝试了有无更改,没有更改c.更改为触发;没有更改ge你能想出其他的选择吗?我能上传一些信息让错误分析更容易吗?它是否有效4 u。只是好奇它是否解决了你的问题。非常感谢你的帮助!我现在有一个跳跃触发器和一个跑步触发器。它工作得很好。
    public class Player : MonoBehaviour

{
    private Rigidbody2D rigid;

    [SerializeField]
    private float jumpForce = 5.0f;
    private bool resetJump;
    [SerializeField]
    private float speed = 5.0f;
    private PlayerAnimation playerAnim;
    private SpriteRenderer playerSprite;

    // Start is called before the first frame update
    void Start()
    {
        ...
    }

    // Update is called once per frame
    void Update()
    {
        Movement();
    }

    void Movement()
    {
        float move = Input.GetAxisRaw("Horizontal");
        Flip(move);

        if (IsGrounded())
        {            
            playerAnim.Jump(false);
        }

        if (Input.GetKeyDown(KeyCode.Space) && IsGrounded() == true)
        {
            rigid.velocity = new Vector2(rigid.velocity.x, jumpForce);            
            StartCoroutine(ResetJumpNeededRoutine());
            playerAnim.Jump(true);
        }        
        rigid.velocity = new Vector2(move * speed, rigid.velocity.y);
        playerAnim.Move(move);
    }

    void Flip(float move)
    {
        ...
    }

    bool IsGrounded()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, Vector2.down, 0.3f, 1 << 8);
        if (hitInfo.collider != null)
        {
            if (resetJump == false)
            {
                return true;
            }
        }
        return false;
    }

    IEnumerator ResetJumpNeededRoutine()
    {
        yield return new WaitForSeconds(0.1f);
        resetJump = false;
    }
}