Picking up chair/box and throw it

I managed it that if the player stands in the trigger collider of the throw object and you hit it that it sends a message to the throw object.
But the throw object should stick to the player until you hit the fire button and throw it away.

this is the code that is attached to the throw object and PickUp() is the function that is triggered from the player object:

#pragma strict
internal var iAmPickedUp:boolean = false;


function Start () {
	
}

function FixedUpdate () {
	if(iAmPickedUp){
		transform.position.x = valueX; //Here should be the x position from the player.. but I don't know how.
		transform.position.y = valueY+heightPlayer; 
	}
}


function PickUp(check:boolean){
	iAmPickedUp = check;
}

Find the PLAYER on start… and use its Position in the FixedUpdaten when needed…

You could, in the Start function, create a reference to the Player object using GameObject.Find() and then when you need to access the x value of the Player you can reference this. Be sure to make a variable to hold the reference and you’ll be all set. Really there is a number of different ways you could do this and I’ve only mentioned the best way I see for what you’re currently working with.

Example:

var thePlayer:GameObject;

function Start() {
    thePlayer = GameObject.Find("Player");
}

function FixedUpdate() {
    if (iAmPickedUp) {
        transform.position.x = thePlayer.transform.position.x;
        transform.position.y = valueY + heightPlayer;
    }
}

I hope this helps,
Mike

Yes yes yes. me happy! Thanks Mike and AlenBrk!