如何在统一日志中打印更新的变量

问题描述 投票:0回答:0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DetectCollision : MonoBehaviour
{
    private int score = 0;
    private int lives = 3;
    // Start is called before the first frame update
       
    void Start()
    {
    }

    // Update is called once per frame
    
    void OnTriggerEnter(Collider other)
    {

        if (other.tag == "food")
        {
            score++;
            Debug.Log(score);
            Destroy(gameObject);
            Destroy(other.gameObject);
        }
        if (other.tag == "Player")
        {
            score--;
            Debug.Log(score);
            if (score == 0)
            {
                Destroy(gameObject);
                Destroy(other.gameObject);
            }
        }

    }
}

每当玩家击中任何动物时,我都会尝试将生命减少一个,并将分数增加一个。如果食物击中动物,但似乎没有其他任何东西起作用不知道为什么。我想更新分数和生命然后打印到日志,如果生命达到 0 则删除玩家。谢谢

c# unity3d
© www.soinside.com 2019 - 2024. All rights reserved.