var layerMask = 1 << 4; //层
var hit : RaycastHit; //光
var hit1: RaycastHit; //光
var hitflag : boolean;
var hitobject : Transform;
function Start()
{
layerMask = ~layerMask; //层取反
hitflag=false;
hitobject=null;
}
function Update ()
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, Mathf.Infinity)&&Input.GetKey (KeyCode.Mouse0))
{
Debug.DrawLine (ray.origin, hit.point);
print(hit.transform.localScale );
if(hit.transform.tag=="Goods") //标签
{
hitflag=true;
hitobject=hit.transform;
}
if (hitflag&&hitobject!=null) //选中物体
{
Physics.Raycast (ray, hit1, Mathf.Infinity,layerMask); //打光
hitobject.position=hit1.point; //物体的坐标等于光2的碰撞点
}
}
if (Input.GetKeyUp (KeyCode.Mouse0))
{
hitflag=false;
hitobject=null;
}
}