首页 > 解决方案 > 出于某种原因,我的玩家没有在我想要的时候传送?

问题描述

在我的游戏中,我想让玩家接触熔岩时受到 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;
    }
}



标签: c#unity3d

解决方案


推荐阅读