unity3d 碰撞时不破坏的对象

agxfikkp  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(226)

子弹在碰撞女巫物品时不会被摧毁,我试着给敌人的物品添加标签,但也不起作用

    • 这是我的子弹代码:**
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);
        }
    }
0x6upsns

0x6upsns1#

private void Oncollisionenter2d(Collision2D collision)

您的碰撞函数名称错误这是正确的一个

private void OnCollisionEnter2D(Collision2D collision)

相关问题