Hi guys i need help with a drag and drop script.
I found this script online - credits to whoever made it.
// -------------------------------------------------------------------------------------------------
// DRAG AND DROP 3D OBJECTS IN AN ORTHOGRAPHIC VIEW
// X AND Z
// SNAP OBJECT TO LOCATION in X Z
//
// SNAP TO LOCATION VIA OCCUPIED LOGIC
// SNAP TO LOCATION VIA ARRAY SHUFFLE
// SNAP TO TWO DISTINCT LOCATIONS
// GAME BOARD LOCATIONS
// HOUSE LOCATIONS
// EACH LETTER HAS A HOUSE, GAMEBOARD AND A CARD REPRESENTING THAT LETTER
// HOUSE OF A
// CARD OF A
// GAMEBOARD OF A
// --------------------------------------------------------------------------------------------------
// CHICKEN DRAG OBJECTS SCRIPT FROM UNITY3D FORUMS
#pragma strict
// Attach this script to an orthographic camera.
private var chicken : Transform; // The chicken we will move.
private var offSet : Vector3; // The chicken's position relative to the mouse position.
function Update () {
var ray = camera.ScreenPointToRay(Input.mousePosition);
// Gets the mouse position in the form of a ray.
if (Input.GetMouseButtonDown(0)) { // If we click the mouse...
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, Mathf.Infinity)) { // Then see if an chicken is beneath us using raycasting.
chicken = hit.transform; // If we hit an chicken then hold on to the chicken.
offSet = chicken.position-ray.origin; // This is so when you click on an chicken its center does not align with mouse position.
if (chicken.rigidbody) {
chicken.rigidbody.isKinematic = true;
}
}
}
else if (Input.GetMouseButtonUp(0)) {
if (chicken.rigidbody) {
chicken.rigidbody.isKinematic = false;
}
chicken = null; // Let go of the chicken.
}
if (chicken) {
chicken.position = Vector3(ray.origin.x+offSet.x, chicken.position.y, ray.origin.z+offSet.z);
// Only move the chicken on a 2D plane.
}
}
This is the original.
My problem with it is that it moves any object that i click on i have tried a few thngs and none of them work. all i want is it to be able to move specific objects and not others. i hope you understand.