- Home /
Question by
jafethjuegos · Nov 19, 2020 at 06:26 PM ·
unity 2dspotlight
How do I make a light (Spotlight) turn to where my character is looking
I want the light to turn to the left when I touch the (A) key and to turn to the right when I touch the (D) key.
I have the light horizontally, not vertical like this normally
I use the light (SpotLight) as a flashlight
I am using unity 2d
Comment
Answer by MurphyMurph_21 · Nov 21, 2020 at 01:47 PM
@jafethjuegos Hey put this together. It works just needs some improvement. Hopefully it will at least give you an idea of how to do it public Light l = new Light();
void Start()
{
l.type = LightType.Spot;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.A))
{
l.transform.eulerAngles += Vector3.right * Time.deltaTime * 100;
}
if (Input.GetKey(KeyCode.D))
{
l.transform.eulerAngles += Vector3.left * Time.deltaTime * 100;
}
}
Your answer
Follow this Question
Related Questions
PUN 2, Player A not seeing Player B's hat 0 Answers
How to make Lights for a car? 1 Answer
Lighting Problem 2 Answers
Making Spotlight rotate on fixed axis 0 Answers
Why is a spotlight giving me a stepped gradient in Unity5? 1 Answer