Home > Mobile >  Firing projectile unity 2d
Firing projectile unity 2d

Time:04-24

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 dont 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.

CodePudding user response:

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.

CodePudding user response:

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
  • Related