The code I have here I need it to be able to click and drag on object. But as far as i can get is clicking the object and it moves once but thats it. Then i have to click again and it moves once again but doesn’t follow the mouse. Heres my code
#pragma strict
static var objectNumber : int; // changes for every object created. Used for makeing each object unique
private var thisObjectsNumber : int; // makes the static variable a non changing private varaible
private var objectName : String; // the name for all objects.
var selectedObject : GameObject; // var for your selected object. This is the object that gets changed.
private var thisObject : GameObject; // sets the game object to this script
var move : boolean;
function Start ()
{
// Gives every object its uniqe name when its created.
objectNumber += 1;
thisObjectsNumber = objectNumber;
objectName = gameObject.name + "# " + objectNumber;
thisObject = gameObject;
thisObject.name = objectName;
}
function Update ()
{
EditMode();
}
function EditMode()
{
if(Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,hit,100))
{
// makes sure to not nullify your object when you click off of it
if(hit.transform.tag == "Game Object")
{
if(hit.transform.name == objectName)
{
selectedObject = GameObject.Find(objectName);
}
if(hit.transform.name != objectName)
{
selectedObject = null;
}
}
if(move == true)
{
if(hit.transform.gameObject == selectedObject)
{
selectedObject.transform.position.x = hit.point.x;
}
}
}
}
}