在下面的代码中,
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Bullet : MonoBehaviour
{
public Rigidbody2D rb;
public int coins;
void Start()
{
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector2(0f, 8f);
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Plane"))
{
coins += 5;
}
}
}
在 OnTriggerEnter2D 函数中,我比较了子弹和飞机,但硬币只增加了 5 一次。因此,如果子弹和飞机再次相撞,它仍然是 5,是的,我已经分配了标签。
我尝试将相同的结果应用于飞机和玩家等其他对象,但结果相同。