I have a script that allows me to move objects in my FPS game with my mouse but I want it to only apply to objects that are in a specific layer so that I dont effect every object, but only ones that are in a specific layer. Can anyone help me add something to my script. I have tried different methods and nothing seems to work as I just have no clue where to add to the script, please can you just add it into my script as others have just given me links to other questions but none of which seem to work. Please can anyone help me?
var grabbed : Transform;
var grabDistance : float = 10.0f;
var useToggleDrag : boolean; // Didn’t know which style you prefer.
function Update () {
if (useToggleDrag)
UpdateToggleDrag();
else
UpdateHoldDrag();
}
// Toggles drag with mouse click
function UpdateToggleDrag () {
if (Input.GetMouseButtonDown(0))
Grab();
else if (grabbed)
Drag();
}
// Drags when user holds down button
function UpdateHoldDrag () {
if (Input.GetMouseButton(0))
if (grabbed)
Drag();
else
Grab();
else
grabbed = null;
}
function Grab() {
if (grabbed)
grabbed = null;
else {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit))
grabbed = hit.transform;
}
}
function Drag() {
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var position : Vector3 = transform.position + transform.forward * grabDistance;
var plane : Plane = new Plane(-transform.forward, position);
var distance : float;
if (plane.Raycast(ray, distance)) {
grabbed.position = ray.origin + ray.direction * distance;
grabbed.rotation = transform.rotation;
}
}