子弹在碰撞女巫物品时不会被摧毁,我试着给敌人的物品添加标签,但也不起作用
- 这是我的子弹代码:**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
private void Oncollisionenter2d(Collision2D collision)
{
Destroy(gameObject);
}
}
- 这是我的武器代码**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
public GameObject bulletPrefab;
public Transform firepoint;
public float fireForce = 20f;
public void Fire()
{
GameObject bullet = Instantiate(bulletPrefab, firepoint.position, firepoint.rotation);
bullet.GetComponent<Rigidbody2D>().AddForce(firepoint.up * fireForce, ForceMode2D.Impulse);
}
}
1条答案
按热度按时间0x6upsns1#
您的碰撞函数名称错误这是正确的一个