亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Unity 中重生后停止死亡動畫

在 Unity 中重生后停止死亡動畫

C#
森林海 2021-05-19 21:22:21
因此,我有一個玩家與敵人碰撞時將開始“傷害”動畫的玩家。2秒后,他將重新生成自己的起始位置,但“傷害”動畫不會停止。即使玩家在四處移動,它也可以繼續播放。這是我的整個播放器腳本:using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class Player : MonoBehaviour{    public float speed = 3.0f;    public Vector2 jumpHeight;    [HideInInspector] public bool facingRight = true;    private float minX = -10.5f;    private float maxX = 10.5f;    public int count;    public Text countText;    private Animator anim;    public GameObject NECText;    public GameObject WinText;    public GameObject player;    void Start()    {        anim = GetComponent<Animator>();        transform.position = new Vector3(-10.0f, -2.32f, 0);        count = 0;        countText.text = "Coins: " + count.ToString();        NECText.gameObject.SetActive(false);        WinText.gameObject.SetActive(false);    }    void Update()    {        Movement();        Death();        float horizontalInput = Input.GetAxis("Horizontal");        if(horizontalInput > 0 && !facingRight)        {            Flip();        }        else if(horizontalInput < 0 && facingRight)        {            Flip();        }    }    void Movement()    {        float horizontalInput = Input.GetAxis("Horizontal");        transform.Translate(Vector3.right * horizontalInput * speed * Time.deltaTime);        if(Input.GetKeyDown(KeyCode.Space)) //fix unlimited jump        {            GetComponent<Rigidbody2D>().AddForce(jumpHeight, ForceMode2D.Impulse);        }        if(transform.position.x < minX)        {            transform.position = new Vector3 (minX, transform.position.y, 0);        }        else if(transform.position.x > maxX)        {            transform.position = new Vector3(maxX, transform.position.y, 0);        }    }    void Death()    {        if (transform.position.y <= -4.25f)        {            anim.SetBool("isHurt", true);            Invoke("Respawn", 2f);        }    }我知道這可能很混亂,但這是我的第一本沒有教程的游戲,所以很難。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 283 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號