[英]Creating a 2D arrow in Unity
I am using unity 2d to create a golf game, currently I have a golf ball that you can click on, drag your mouse back and let go to fire the ball. 我正在使用unity 2d制作高尔夫游戏,目前我有一个高尔夫球,可以单击它,将鼠标向后拖动,然后放开球。 I would like to add an arrow that starts where you click and ends where you let go to see the direction of aim.
我想添加一个箭头,该箭头从您单击的位置开始,到您放开以查看目标方向的位置结束。
I cannot seem to find any documentation on how to do this or where to begin. 我似乎找不到任何有关如何执行此操作或从何开始的文档。 Any help on this or if you could push me in the right direction I would appreciate it.
在此方面的任何帮助,或者如果您可以将我推向正确的方向,我将不胜感激。
It sounds like you want to create a world-space UI canvas and draw an arrow on it. 听起来您想创建一个具有世界空间的UI画布并在其上绘制箭头。 There are many ways you can do the second half, but a good place to start would be to get a UI canvas in there and start toying with ways that you can make objects in that behave.
下半部有很多方法,但是一个好的开始是将UI画布放到那里,然后开始尝试使该对象行为的方式。
For more on world-space UI, refer here . 有关世界空间用户界面的更多信息,请参见此处 。
You need to save the position where you click. 您需要保存点击位置。 You can get the mouse position with Input.mousePosition.
您可以使用Input.mousePosition获取鼠标位置。 More information about this here .
关于这方面更多的信息在这里 。 While holding the click, you have to store a second mouse position, this one will save the current position.
按住单击时,您必须存储第二个鼠标位置,该位置将保存当前位置。 Use, for example, a LineRenderer linking both positions.
例如,使用链接两个位置的LineRenderer 。 If you want the arrow aiming to the opposite direction ie the position where the ball will be fired, just set the second position to negative.
如果您希望箭头指向相反的方向,即将球发射的位置,只需将第二个位置设置为负数即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.