- 最后登录
- 2020-3-16
- 注册时间
- 2014-4-17
- 阅读权限
- 90
- 积分
- 7683
 
- 纳金币
- 2378
- 精华
- 0
|
1.首先从互联网上下载一个准星图片,并将其拖入到Unity工程中,然后编写以下代码:
using UnityEngine;
using System.Collections;
public class DrawStar : MonoBehaviour {
public Texture2D texture;
// Use this for initialization
void OnGUI()
{
Rect rect = new Rect(Input.mousePosition.x - (texture.width/2),
Screen.height - Input.mousePosition.y - (texture.height/2),
texture.width, texture.height);
GUI.DrawTexture(rect, texture);
}
}
2.把脚本拖曳到主相机上,把工程中的图片拖曳到主相机的Texture下,运行程序,移动鼠标就会发现准星跟随鼠标移动,如图1-1所示:
|
|