简体   繁体   中英

Firing projectile unity 2d

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM