因此,我有一个玩家与敌人碰撞时将开始“伤害”动画的玩家。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 关注
- 261 浏览
添加回答
举报
0/150
提交
取消