Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Getting muzzle flash to come out of the end of my gun

Discussion in 'General Graphics' started by ashivji, Feb 28, 2015.

  1. ashivji

    ashivji

    Joined:
    Nov 9, 2013
    Posts:
    1
    Hi All,
    Very new to unity and messing around with some effects I purchased from the asset store. I have a basic FPS style game and I can current get the muzzle flash to come out of my face but not from my gun muzzle. I have the gun as a child of the camera in first person view so it just kinda floats around with the camera view. My code is as follows to get the effect to show:

    Instantiate(flash, Camera.main.transform.position, Camera.main.transform.rotation);

    I have tried adding a Vector3 object to the camera position but this seems to screw up the rotation. I also tried putting a empty GameObject on the end of my gun but I don't know how to access its location from my script.
     
  2. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    227
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Agree with varfare - and you could also parent the muzzle flash to the end of your gun by dragging it onto the gun object in the hierarchy panel. Or parent the empty game object to the gun - reposition as needed and parent the muzzle flash to the empty game object.