So I’m pretty new to unity and scripting in total but I am making a simple spaceshooter game.
Now I want to add a sun that gives damage over time and the closer the player gets to the sun the more damage they get.
I use C# it would be really nice if someone could help me because I couldnt find this anywhere,
Thank you!
-Sky
Well, assuming you don’t have some sort of cover system from the sun (although, if you did want to use a cover system you could just use Unity’s built in tag + triggerstay systems, although they can be a bit slow) anyways, back to topic, I would use
Vector3.Distance
Use it to calculate distance, and devise formula to calculate sun damage
So something like this:
damage = 50 / Vector3.Distance (player.transform.position, sun.transform.position)
Ah I forgot to mention that it is a 2D project! thanks for the reply.
No problem, there is also Vector2.Distance that should still suit your needs,
1 Like