var GO:GameObject;
static var pointx:float;
static var pointy:float;
static var pointz:float;
function Start (){
pointx=GO.transform.position.x;
pointy=GO.transform.position.y;
pointz=GO.transform.position.z;
}
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
Debug.DrawLine (ray.origin, hit.point);
print(hit.transform.name);
}
if(Input.GetKey(KeyCode.Mouse0)){
pointx=hit.point[0];
pointy=hit.point[1];
pointz=hit.point[2];
}
if(Input.GetKey(KeyCode.W)){
pointx=GO.transform.position.x;
pointy=GO.transform.position.y;
pointz=GO.transform.position.z;
}
if(Input.GetKey(KeyCode.S)){
pointx=GO.transform.position.x;
pointy=GO.transform.position.y;
pointz=GO.transform.position.z;
}
if(Input.GetKey(KeyCode.A)){
pointx=GO.transform.position.x;
pointy=GO.transform.position.y;
pointz=GO.transform.position.z;
}
if(Input.GetKey(KeyCode.D)){
pointx=GO.transform.position.x;
pointy=GO.transform.position.y;
pointz=GO.transform.position.z;
}
if(Mathf.Round(pointx-GO.transform.position.x)>0){
GO.transform.position.x+=2*Time.deltaTime;
}
else if(Mathf.Round(pointx-GO.transform.position.x)<0){
GO.transform.position.x+=-2*Time.deltaTime;
}
if(Mathf.Round((pointy+GO.transform.localPosition.y)-GO.transform.position.y)>0){
GO.transform.position.y+=1*Time.deltaTime;
}
else if(Mathf.Round((pointy+GO.transform.localPosition.y)-GO.transform.position.y)<0){
GO.transform.position.y+=-1*Time.deltaTime;
}
if(Mathf.Round(pointz-GO.transform.position.z)>0){
GO.transform.position.z+=2*Time.deltaTime;
}
else if(Mathf.Round(pointz-GO.transform.position.z)<0){
GO.transform.position.z+=-2*Time.deltaTime;
}
}