我編寫了以下代碼來損壞我的播放器,但是它不起作用。我已經(jīng)盡可能多地檢查了編碼錯誤,我知道我的問題是標(biāo)簽。使用 Debug.log 功能,我能夠確認(rèn)問題不在于我的命中框,并且標(biāo)簽設(shè)置正確。相同的系統(tǒng)反過來對我的玩家彈丸造成傷害。但是,使用我的播放器進行設(shè)置時它不起作用。using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class DamageToPlayer : MonoBehaviour {public float damageAmount;public void OnCollisionEnter(Collision col) { if(col.gameObject.tag == "Player") { Debug.Log("nearlyThere"); PlayerHealth ifPlayer = col.gameObject.GetComponent<PlayerHealth>(); if(ifPlayer != null) { ifPlayer.PlayerDamage(damageAmount); Debug.Log("TOUCH"); } }}這是敵人的密碼。}using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class PlayerHealth : MonoBehaviour {public float PlayerStartHealth;public float playerHealth;public Text text;public void Start () { playerHealth = PlayerStartHealth;} public void PlayerDamage(float pAmount){ playerHealth -= pAmount; if (playerHealth <= 0) { EndLevel(); }}public void EndLevel(){ Debug.Log("u died m8");}public void FixedUpdate(){ text.text = playerHealth.ToString();}這是更多信息:控制臺上沒有出現(xiàn)任何調(diào)試。這就是我知道問題的方式。}這是玩家健康碼本身。我不知道為什么這不起作用。
- 1 回答
- 0 關(guān)注
- 266 瀏覽
添加回答
舉報
0/150
提交
取消