用鼠标在屏幕上拖动多张图片
来源:互联网 发布:淘宝口令红包 编辑:程序博客网 时间:2024/05/16 23:47
以前看过一段代码,说的是用鼠标在屏幕上拖动图片,但这段代码的扩展性不是很好,拖动任何位置,图片都会移动,且只能拖动一张图片。代码如下:
var Tu : Texture2D;
private var first = Vector2.zero;
private var second = Vector2.zero;
private var tempx : float = 0;
private var tempy : float = 0;
function OnGUI () {
GUI.DrawTexture (Rect (tempx, tempy, 50, 50),Tu);
if(Event.current.type == EventType.MouseDown){
first = Event.current.mousePosition ;
}
if(Event.current.type == EventType.MouseDrag){
second = Event.current.mousePosition ;
tempx += (second.x-first.x);
tempy += (second.y-first.y);
first = second;
}
}
function Update () {
}
下面贴一段我修改后的代码,这段代码可以实现鼠标必须点击在图片上才能拖动图片,且可以拖动多张图片。拖动某一张图片时,其他图片不会收影响。利用这个思想,你可以实现其他的很多功能,不仅仅是拖动图片,例如可以实现判断图片是否拖入某一正确区域等等(拼图游戏可以用上述方法实现)。
var Tu : Texture2D;
var Tu1 : Texture2D;
private var first = Vector2.zero;
private var second = Vector2.zero;
private var tempx : float = 0;
private var temp1x : float = 500;
private var tempy : float = 0;
private var temp1y : float = 0;
var IsTu : int = 0;
var IsTu1 : int = 0;
function Update () {
}
function OnGUI () {
GUI.DrawTexture (Rect (tempx, tempy, 50, 50),Tu);
GUI.DrawTexture (Rect (temp1x, temp1y, 50, 50),Tu1);
if(Event.current.type == EventType.MouseDown){
first = Event.current.mousePosition ;
}
if(first.x > tempx && first.x < (tempx+50) && first.y > tempy && first.y < (tempy+50) ){
IsTu = 1;
}
if(first.x > temp1x && first.x < (temp1x+50) && first.y > temp1y && first.y < (temp1y+50) ){
IsTu1 = 1;
}
if(Event.current.type == EventType.MouseDrag && IsTu == 1){
second = Event.current.mousePosition ;
tempx += (second.x-first.x);
tempy += (second.y-first.y);
first = second;
IsTu = 0;
}
if(Event.current.type == EventType.MouseDrag && IsTu1 == 1){
second = Event.current.mousePosition ;
temp1x += (second.x-first.x);
temp1y += (second.y-first.y);
first = second;
IsTu1 = 0;
}
}
//~ function Update () {
//~ }
- 用鼠标在屏幕上拖动多张图片
- 用鼠标拖动图片
- 在game屏幕拖动图片
- 用NGUI显示图片鼠标点击的地方出现在屏幕上
- 用鼠标拖动图片移动
- 用鼠标拖动图片移动
- demo_用鼠标拖动图片
- 鼠标在屏幕上乱动
- 禁止鼠标拖动图片在新窗口打开
- 可以拖动的多张图片
- Unity_在屏幕中拖动图片_067
- 图片(多张)横向滚动,当鼠标停放在其中一张图片时,此张图片发大,滚动停。
- 在struts2框架上上传多张图片
- Control Study -> 实现:用鼠标拖动图片
- Control Study -> 实现:用鼠标拖动图片
- Control Study -> 实现:用鼠标拖动图片
- 鼠标拖动图片-javascript
- C# 鼠标拖动图片
- 单击鼠标左键 物体朝向点击点
- 研究Html中自定义属性(一)
- 魔兽视角
- 动态加载贴图和模型
- 鼠标操纵角色
- 用鼠标在屏幕上拖动多张图片
- 物体变成其他物体的子物体
- 分包加载
- 用C#下载图片
- 截屏脚本
- 【转】AI_自动寻怪,自动追击
- 【转】帮助GUI的制作(可以开关图片或视频)
- Unity 3d 后代生成LineRenderer线
- 【原】各种shader实现,上图