英语不好,不要介意。
using UnityEngine;
using System.Collections;
public class wuping : MonoBehaviour {
public class WuPing//物品类
{
public float wuping_x=0;//图标的x坐标
public float wuping_y=0;//图标的Y坐标
public Texture tubiao;//物品图标
public Texture shuxing;//物品属性图
public bool anxia=false ;//判断是否按下
public bool xianshishuxt=false ;//是否显示属性图
public void fun()
{
GUI.DrawTexture (new Rect (wuping_x ,wuping_y ,50,50), tubiao );
}
public void fun1()
{
if (xianshishuxt ==true )
{
GUI.DrawTexture (new Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y,250,300), shuxing );
}
}
}
public class BeiBao
{
public float beibao_x;
public float beibao_y;
public Texture beibao;//背包图片
public bool weizi=false ;
public void beibaofun()
{
GUI.DrawTexture (new Rect (beibao_x,beibao_y,50,50),beibao);
}
}
public Texture beibaotu;
public Texture[] tupian=new Texture[4] ;
BeiBao [,]bao=new BeiBao [3,5];
WuPing[] a=new WuPing[2] ;
Texture wupin1;
float x=0;
float y=0;//图标的Y坐标
float x1=0;//鼠标的X坐标
float y1=0;//鼠标的Y坐标
// Use this for initialization
void Start () {
a[0]=new WuPing ();
a[0].tubiao =tupian [0];
a[0].shuxing =tupian [1];
a[1]=new WuPing ();
a[1].wuping_x =100;
a[1].wuping_y =100;
a[1].tubiao =tupian [2];
a[1].shuxing =tupian [3];
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
bao[i,j]=new BeiBao ();
}
}
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
y1=(Screen.height-Input.mousePosition.y-25);
x1=(Input.mousePosition.x-25);
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
bao[i,j].beibao =beibaotu ;
bao[i,j].beibao_x =500+j*50;
bao[i,j].beibao_y =300+i*50;
bao[i,j].beibaofun ();
}
}
for (int i=0;i<2;i++)
{
if (a[i].wuping_x -25<x1 && a[i].wuping_x +25>x1 && a[i].wuping_y -25<y1 && a[i].wuping_y +25>y1)
{
a[i].xianshishuxt =true ;
if (Input .GetMouseButtonDown (0))
{
a[i].anxia =true ;
}
}
else
{
a[i].xianshishuxt =false ;
}
if(a[i].anxia ==false )
{
a[i].fun ();
a[i].fun1 ();
}
if (a[i].anxia ==true )
{
a[i]=YouXiWuPing(a[i]);
a[i].fun ();
a[i].fun1 ();
}
}
print (bao[1,1].weizi );
}
WuPing YouXiWuPing(WuPing b)
{
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
if(b.wuping_x ==bao[i,j].beibao_x &&b.wuping_y ==bao[i,j].beibao_y )
{
bao[i,j].weizi =false ;
}
}
}
x=b.wuping_x ;
y=b.wuping_y ;
b.xianshishuxt =false ;
if (Input .GetMouseButtonUp(0))
{
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
if(x1+25>=500+j*50&&x1+25<=500+j*50+50&&y1+25>=300+i*50&&y1+25<=300+i*50+50&&b.anxia ==true)
{
if(bao[i,j].weizi ==false )
{
x=bao[i,j].beibao_x ;
y=bao[i,j].beibao_y ;
bao[i,j].weizi =true ;
break ;
}
if(bao[i,j].weizi ==true )
{
for (int ii=0;ii<3;ii++)
{
for (int jj=0;jj<5;jj++)
{
if(bao[ii,jj].weizi ==false )
{
x=bao[ii,jj].beibao_x ;
y=bao[ii,jj].beibao_y ;
bao[ii,jj].weizi =true ;
break ;
}
}
}
}
}
if(x<500||y<300||x>725||y>425 )
{
if(bao[i,j].weizi ==false )
{
x=bao[i,j].beibao_x ;
y=bao[i,j].beibao_y ;
bao[i,j].weizi =true ;
break ;
}
}
}
}
b.anxia =false ;
}
if (b.anxia ==true )
{
y=y1;
x=x1;
}
b.wuping_x =x;
b.wuping_y =y;
return b;
}
}
using UnityEngine;
using System.Collections;
public class wuping : MonoBehaviour {
public class WuPing//物品类
{
public float wuping_x=0;//图标的x坐标
public float wuping_y=0;//图标的Y坐标
public Texture tubiao;//物品图标
public Texture shuxing;//物品属性图
public bool anxia=false ;//判断是否按下
public bool xianshishuxt=false ;//是否显示属性图
public void fun()
{
GUI.DrawTexture (new Rect (wuping_x ,wuping_y ,50,50), tubiao );
}
public void fun1()
{
if (xianshishuxt ==true )
{
GUI.DrawTexture (new Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y,250,300), shuxing );
}
}
}
public class BeiBao
{
public float beibao_x;
public float beibao_y;
public Texture beibao;//背包图片
public bool weizi=false ;
public void beibaofun()
{
GUI.DrawTexture (new Rect (beibao_x,beibao_y,50,50),beibao);
}
}
public Texture beibaotu;
public Texture[] tupian=new Texture[4] ;
BeiBao [,]bao=new BeiBao [3,5];
WuPing[] a=new WuPing[2] ;
Texture wupin1;
float x=0;
float y=0;//图标的Y坐标
float x1=0;//鼠标的X坐标
float y1=0;//鼠标的Y坐标
// Use this for initialization
void Start () {
a[0]=new WuPing ();
a[0].tubiao =tupian [0];
a[0].shuxing =tupian [1];
a[1]=new WuPing ();
a[1].wuping_x =100;
a[1].wuping_y =100;
a[1].tubiao =tupian [2];
a[1].shuxing =tupian [3];
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
bao[i,j]=new BeiBao ();
}
}
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
y1=(Screen.height-Input.mousePosition.y-25);
x1=(Input.mousePosition.x-25);
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
bao[i,j].beibao =beibaotu ;
bao[i,j].beibao_x =500+j*50;
bao[i,j].beibao_y =300+i*50;
bao[i,j].beibaofun ();
}
}
for (int i=0;i<2;i++)
{
if (a[i].wuping_x -25<x1 && a[i].wuping_x +25>x1 && a[i].wuping_y -25<y1 && a[i].wuping_y +25>y1)
{
a[i].xianshishuxt =true ;
if (Input .GetMouseButtonDown (0))
{
a[i].anxia =true ;
}
}
else
{
a[i].xianshishuxt =false ;
}
if(a[i].anxia ==false )
{
a[i].fun ();
a[i].fun1 ();
}
if (a[i].anxia ==true )
{
a[i]=YouXiWuPing(a[i]);
a[i].fun ();
a[i].fun1 ();
}
}
print (bao[1,1].weizi );
}
WuPing YouXiWuPing(WuPing b)
{
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
if(b.wuping_x ==bao[i,j].beibao_x &&b.wuping_y ==bao[i,j].beibao_y )
{
bao[i,j].weizi =false ;
}
}
}
x=b.wuping_x ;
y=b.wuping_y ;
b.xianshishuxt =false ;
if (Input .GetMouseButtonUp(0))
{
for (int i=0;i<3;i++)
{
for (int j=0;j<5;j++)
{
if(x1+25>=500+j*50&&x1+25<=500+j*50+50&&y1+25>=300+i*50&&y1+25<=300+i*50+50&&b.anxia ==true)
{
if(bao[i,j].weizi ==false )
{
x=bao[i,j].beibao_x ;
y=bao[i,j].beibao_y ;
bao[i,j].weizi =true ;
break ;
}
if(bao[i,j].weizi ==true )
{
for (int ii=0;ii<3;ii++)
{
for (int jj=0;jj<5;jj++)
{
if(bao[ii,jj].weizi ==false )
{
x=bao[ii,jj].beibao_x ;
y=bao[ii,jj].beibao_y ;
bao[ii,jj].weizi =true ;
break ;
}
}
}
}
}
if(x<500||y<300||x>725||y>425 )
{
if(bao[i,j].weizi ==false )
{
x=bao[i,j].beibao_x ;
y=bao[i,j].beibao_y ;
bao[i,j].weizi =true ;
break ;
}
}
}
}
b.anxia =false ;
}
if (b.anxia ==true )
{
y=y1;
x=x1;
}
b.wuping_x =x;
b.wuping_y =y;
return b;
}
}