Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Flashlight Moving With Camera

Discussion in 'Scripting' started by Corrothon, Aug 17, 2020.

  1. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    I'm working on a horror game blah blah anyways, I've made a flashlight and I want it to move with the mouse. Any help?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,950
    What kind of movement do you mean? Is this a first person game? Third person? Top-down? Need more details to help.
     
  3. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    First person Game :) I want the flashlight to move with the camera
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,950
    Is your camera already moving with the mouse? If so, just make the flashlight a child object of the camera. No script required!
     
  5. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Really? If you don't mind me asking how can I make the flashlight a child obj?
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,950
    in the Hierarchy just drag the flashlight object over the camera object. The flashlight will become a child of the camera. When it's a child it will inherit all the movement and rotation of the camera automatically.

    You can read more about it on this page: https://docs.unity3d.com/Manual/Hierarchy.html
     
  7. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Thank you!