I need to move a object with the tag Respawn to the object with the tag Hand when i press a GUI Texture.I have this script.
var topick : GameObject;
topick = GameObject.Find ("Hand");
var AttractOn = 0;
var smooth = 1.0;
// the tag to search for (set this value in the inspector)
var searchTag = "Respawn";
// the frequency with which to re-scane for new nearest target in seconds
// (set in inspector)
var scanFrequency = 1.0;
// the current target
private var target : Transform;
function Start() {
// set up repeating scan for new targets:
InvokeRepeating("ScanForTarget", 0, scanFrequency );
}
function onMouseDown() {
AttractOn = 1;
}
function Update() {
// we rotate to look at the target every frame (if there is one)
if (target != null) {
//Code for attract
}
}
function ScanForTarget() {
// this should be called less often, because it could be an expensive
// process if there are lots of objects to check against
target = GetNearestTaggedObject();
}
function GetNearestTaggedObject() : Transform {
// and finally the actual process for finding the nearest object:
var nearestDistanceSqr = Mathf.Infinity;
var taggedGameObjects = GameObject.FindGameObjectsWithTag(searchTag);
var nearestObj : Transform = null;
// loop through each tagged object, remembering nearest one found
for (var obj : GameObject in taggedGameObjects) {
var objectPos = obj.transform.position;
var distanceSqr = (objectPos - transform.position).sqrMagnitude;
if (distanceSqr < nearestDistanceSqr) {
nearestObj = obj.transform;
nearestDistanceSqr = distanceSqr;
}
}
return nearestObj;
}
if (gameObject.tag == "Respawn"){
transform.position = Vector3.Lerp(transform.position,topick.transform.position,Time.deltaTime*smooth);
}
It’s not an error, but it’s doesn’t do anything.
I put this script on the GUI Texture.
Please help
I delayed one day for this homework
P.S. I use android, joystick and FirstPersonControl scripts from Standard Assets(Mobile)