查看: 1287|回复: 0
打印 上一主题 下一主题

基于gui的拖动图片效果

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-2-20 13:47:12 |只看该作者 |倒序浏览
这段代码可以实现鼠标必须点击在图片上才能拖动图片,且可以拖动多张图片。拖动某一张图片时,其他图片不会收影响。
        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;

   }

  }



转自:unity3d8.com
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-2-23 02:04 , Processed in 0.478469 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部