So I have a script going that sorta half works as intended. The way I need it to work is the object will follow the mouse around as long as the left mouse button is held, however as I have it, the object will only move to a different position within it's own Collision box.
Here's the script :
#pragma strict
public var atom : GameObject;
function Update () {
var v3T = Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
v3T = Camera.main.ScreenToWorldPoint (v3T);
if(Input.GetMouseButtonDown(0)){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit)){
if(hit.collider.tag == "Atom"){
Debug.Log(hit.collider.gameObject.name);
atom = hit.collider.gameObject;
atom.transform.position = v3T;
}
}
}
if(Input.GetButtonUp("Fire1")){
atom = null;
Debug.Log("Object Dropped");
}
}
Just to be clear, the way I want it to work is the object will follow the mouse around while the left mouse button is pressed, and will simply stop following once the mouse button is no longer pressed and will stay in that position.
Any help is greatly appreciated.
↧