Is it possible to make a script to spotlight making the light turn on depending on the sun position? I made a rotation script to the sun (to simulate sunset and sunrise) which the sun rotate from top position of Y=500 to bottom position of Y= -500. I would like to make a script to spotlight making it to turn on when the sun position is between -500 to 60 at Y axit but its not working..any help?
You need to create a script (let's call it lightManager.cs) which will keep reference of all your spotlight in a list or array. You need also a reference to your sun transform. You can check your specific sun condition in the update loop per example and call a function to loop over your light to turn them on / off
A better solution could be to fire an event when the night fall / the day rise. It's a bit more complicated if you are not comfortable with coding but it could be useful if you have other task to do (than deal with the light) when night comes
Its actually my first week in unity so im very unfamiliar with these options. I really dont know how to start the script which is action thepends on other object (the sun)
The way I handled this is by having a script that tracks in game time of day, and adjusts the rotation of the sun accordingly, rather than trying to track the rotation of the sun itself.(because euler angles can get weird at some rotations). Since I've got the time of day, I split that up into 4 main phases (night, dawn, day, dusk), as well as transition phases between them. Then I just turn things like lights on and off depending on the phase.
I don't think I reached this level of understanding in unity yet. im very noob, only about one week and first I want to understand the basic scripting. right now I have very simple script of rotation of the sun and im pretty satisfied with it. I really want to understand how scripting of light that turning on and of depending on the sun Y axis position looks like
I can set up a demo scene of the solutions i described above but right now i'm having no time. my advice would be to feed yourself with youtube tutorials. Whatever the subject of the tutorial, you will have a better overview of how things work in unity and you will be able to imagine and code your own solution
Thats what i did but all of the tutorials is about making a switch. Its much harder to find tutorials of "Kayboard free" commands in unity
The problem is if you just rotate an object around a single axis you'll often see the rotation values of other axis change as well, making the value of that one axis rotation you care about not be what you expect it should. This is because internally the rotation is stored as a Quaternion, instead of the more easy to understand x/y/z euler angles. So reading the rotation value of a single axis and using that to determine how far it has rotated often does not work.
But anyway i dont think i can handle your solution..i can only write single simple script right now. And I didnt find any tutorials explaining how to make object X to act depending on object Y condition