c# - 出于某种原因,我的玩家没有在我想要的时候传送?
问题描述
在我的游戏中,我想让玩家接触熔岩时受到 10 点伤害并在空中移动 200 米。我的问题是他不动。我对此知之甚少,但我做了我认为可行的事情,但由于某种原因它没有。我知道这是因为玩家受到了伤害。所以问题出在代码上。唯一应该相关的部分是 HitLava 底部的代码。我包含了其他代码以防万一。谢谢!
我的代码:(对不起,如果不好,我是编程菜鸟)
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine;
public class Healths : MonoBehaviour
{
public float healthPoints = 100.0f;
private Coroutine onHit = null;
private Coroutine onHitLava = null;
private Coroutine onHeal = null;
public GameObject Player;
private float xpos;
private float zpos;
private float ypos;
private void Update()
{
StartCoroutine(Updaate());
if (onHeal == null)
onHeal = StartCoroutine(HealthRegen());
}
IEnumerator Updaate()
{
if (healthPoints <= 0)
{
// SceneManager.LoadScene("Game_Over"); change to go to checkpoint
}
if (healthPoints >= 101.0f)
{
healthPoints = 100.0f;
}
yield return new WaitForSeconds(2.0f);
}
private void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.tag == "Zombie")
{
if (onHit == null)
onHit = StartCoroutine(HitDelay());
}
if (coll.gameObject.tag == "Lava")
{
if (onHitLava == null)
onHitLava = StartCoroutine(HitLava());
}
}
IEnumerator HitDelay()
{
healthPoints = healthPoints - 15;
yield return new WaitForSeconds(2.0f);
onHit = null;
}
IEnumerator HealthRegen()
{
healthPoints = healthPoints + 1;
yield return new WaitForSeconds(1.0f);
onHeal = null;
}
IEnumerator HitLava()
{
healthPoints = healthPoints - 10;
zpos = Player.transform.position.z;
xpos = Player.transform.position.x;
ypos = Player.transform.position.y + 200;
Player.transform.position = new Vector3(xpos, ypos, zpos);
yield return new WaitForSeconds(1.0f);
onHit = null;
}
}
解决方案
推荐阅读
- kubernetes - Helm 2 an Helm 3 in the same cluster?
- css - Vue: Extract CSS - Didn't get a result from child compiler
- javascript - Fetch data from program and display them in HTML
- angular - Firebase - 检查项目名称是否存在
- python-3.x - 遍历 N 个嵌套列表和字典
- asp.net - 如何将 2 个对象发送到我的 API (ASP.NET)?
- javascript - Passport js 本地策略:TypeError:LocalStrategy 需要验证回调
- sharepoint-online - 在超链接字段上的 SharePoint 列表中查找项目
- javascript - 创建新的 React 应用程序时出现错误
- javascript - 使用 API 获取未定义的响应