W
W
Wadim_wadim20002020-06-01 19:53:37
C++ / C#
Wadim_wadim2000, 2020-06-01 19:53:37

Unity how to formulate this in a script?

Most likely no one will help me with this ... But still, I hope so.
Can anyone help write this as a c# script?
Here's what you need to write down:
Variables:
There are 3 gameObjects that are:
Player
Middle of the arrow
End of the arrow

And variable float offset

This means that the mouse is clicked on the screen and an arrow should be drawn from the player there. This is where I need your help. I think it's done like this.

We find the coordinates of the mouse click, find the difference in coordinates with the player (vector) and equate the transform of the middle of the arrow to this place. Next, we find the angle of rotation of the click relative to the sprite, and rotate the middle of the arrow to this angle. Then, stretch it along x (distance, 0f, 0f). And we put the end of the arrow on the coordinates of the click - offset and turn it to the same angle.

I probably bothered you in vain, but if there is someone who writes such a script, please write!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question