【发布时间】:2023-01-15 02:31:03
【问题描述】:
我有一个射弹和一个敌人,但我希望敌人在接触射弹时减少健康变量。
我试着发射射弹,但它并没有降低生命值。
`使用系统集合; 使用 System.Collections.Generic; 使用统一引擎;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Health : MonoBehaviour
{
public int startHealth = 20;
public int health;
// Start is called before the first frame update
void Start()
{
health = startHealth;
}
// Update is called once per frame
void OnTriggerEnter2D(Collider2D col)
{
Debug.Log("Hit");
if (col.gameObject.tag == "PlayerProjectile")
{
health = health - 1;
}
}
void LateUpdate()
{
if (health < 1)
{
Destroy(gameObject);
}
}
}
【问题讨论】:
标签: unity3d 2d projectile