WOW lots of different attempts on how to do this(previous questions) this question might work. I have a block(call it block1) and I want it to appear in the other block(block2) position when I look at it no matter where it is(with the first person view).
Use a raycast from the player camera to determine what the player is looking at, and then call a sendMessage() on that object. Then intercept the send message in a script on your Block1 so that it moves to Block2.
Because you asked for a script (though I highly recommend also learning these things for yourself, and in general the answers are not a place to get other people to write scripts for you):
In your camera controller put
function Update()
{
var hit: RaycastHit;
if(Physics.Raycast(transform.position, transform.forward, hit)) //returns a hit object
{
//tell the hit object it was looked at
hit.transform.SendMessage("Look", SendMessageOptions.DontRequireReceiver); //so we don't get errrors if the message is not caught
}
}
And then in your box object have something like:
var box2: GameObject; //Put box2 into the inspector for this variable
function Look()
{
transform.postion = box2.transform.position; //move the current object, Box 1 to box 2
}
And that should do it.