[英]How to draw a crosshair in Unity (2D)
I have a Player class with an OnGUI()
method, in which I'm calculating the position of a crosshair I want to draw. 我有一个带有
OnGUI()
方法的Player类,在其中计算要绘制的十字准线的位置。 Also in the same scene, I have a Canvas GameComponent called Crosshair (on the UI layer), which has an Image child which contains the crosshair sprite/image. 同样在同一场景中,我有一个名为Crosshair(在UI层上)的Canvas GameComponent,它具有一个Image子对象,其中包含Crosshair子画面/图像。 I haven't been able to find this anywhere, but how do I tell the code in
OnGUI()
to take this Crosshair object and render it at a specific position? 我一直无法在任何地方找到它,但是我如何告诉
OnGUI()
的代码采用此Crosshair对象并将其呈现在特定位置? Old answers suggest using Texture2D
but that's been deprecated by now... 旧答案建议使用
Texture2D
但现在已不建议使用...
Please check if you are converting the position of your crosshair from world to screen By using Camera.ScreenToWorldPoint . 请使用Camera.ScreenToWorldPoint检查是否将十字准线的位置从世界转换为屏幕。
Also look at the link https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html 还要查看链接https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.