Firing projectile in Unity 2D

1k Views Asked by At

I am trying to make the character fire some waves through the weapon when you click the mouse button, but somehow the waves (projectiles) are not showing in the screen even though the hierarchy shows that its being cloned. I'm new to Unity so I don't understand what's the problem.

This is the code I'm using:

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

public class weapon : MonoBehaviour
{
  public GameObject projectile; 
  public Transform shotPoint;

  private void Update()
  {
    if(Input.GetMouseButtonDown(0)){
      Instantiate(projectile, shotPoint.position, transform.rotation);
    }
  }
}

I'd be thankful if someone can help me.

3

There are 3 best solutions below

0
On

I would try what Sven Viking suggested, but also check the order in layer of the bullet clone. Sometimes it might just be hidden behind another object or the background. Additionally, try setting the speed of the bullet to 0, it might just be that the bullet is moving too fast.

0
On

A few things:

  • Make sure you're rendering the projectile prefab to the same layer as the camera
  • Make sure rendering components are set to enabled
  • Make sure that your objects are rendering to the correct z value as I believe that can cause errors rendering
0
On

check the size of it and make sure it has rigid body make sure it is textured or that its not invisible and that you are using transform.translate