Problem in shooting object(my bullet doesn’t detect the object )

Updated on October 11, 2018 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on October 11, 2018

#Bullet Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet2 : MonoBehaviour {

public float speed = 20f;

public Rigidbody2D rb;

// Use this for initialization
void Start () {
rb.velocity = transform.up * speed;
}

void OnTriggerEnter2D(Collider2D hitInfo)
{
Debug.Log(hitInfo.name);
Destroy(gameObject);
}

}

 

#Weapon Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Weapon : MonoBehaviour {

public Transform firepoint;
public GameObject bulletPrefab;

// Update is called once per frame
void Update () {

if(Input.GetButtonDown(“Fire1”))
{

Shoot();
}
}

void Shoot ()
{

//Shooting Logic
Instantiate(bulletPrefab, firepoint.position, firepoint.rotation);
}
}

  • Liked by
Reply
0 on October 11, 2018

Did you try to rb.iskinematic checked? I am not exactly sure.

  • Liked by
Reply
Cancel
0 on October 11, 2018

Does the bullet, or whatever you’re shooting, have a Collider2D set to trigger?

  • Liked by
Reply
Cancel