Object Manipulation

I am making a first-person game for a project that deals with manipulating objects, ex: carry a box onto a button to open a door. I understand the jest of what I need to do:

check collision with the object and the player, have a keystroke trigger the “pick up”, make the object a child of the player, make another keystroke trigger the “drop”, check with collision of the object and the button (I would like the button to give a little under the weight of the object but I am unsure how to do this), this will trigger the animation of the doors to open.

I am unsure of how to script this. Any help will be greatly appreciated.

How about this:

Give the script an OnCollisionEnter and an OnCollisionExit event. In the OnCollisionEnter, check the colliding object and see if it is the appropriate “key” that presses the button. If so, move the button down slowly. When it reaches the bottom trigger your event. In the OnCollisionExit event, undo the move and undo the trigger event.

So, you pick up a box, take it accross the room to a waiting collider. You drop the box on the collider and it sinks just a little and opens a doorway. Pick the collider back up, and it raises, and closes the doorway.

Are you saying that the button would go up and down from a triggered animation?

Thank you for the help, however, I still do not know how to script this at all.

No, its mathematical. Also, you should be running a coroutine to handle the button and activations.

Psuedo code (yes, I am writing it so that you have to write the actual code)

door : Transform
doorMove=Vector3(2,0,0) // direction the door moves
buttonMove=Vector3(0,-0.2, 0)// direction the button moves
dobutton=false

Star(){
	StartCoroutine(DoButton)
}

DoButton(){
	buttonStart=transform.position
	doorStart=door.position
	while true{
		if(dobutton){
			// start the buttonmoving down
			transform.position=Vector3.Lerp(buttonStart, buttonStart + buttonMove, 1.0 * Time.deltaTime)
			if(Vector3.Distance(transform.position, buttonStart + buttonMove) < 0.01){
				door.position=Vector3.Lerp(doorStart, doorStart + doorMove, 2.0 * Time.deltaTime)
			}
		} else {
			transform.position=Vector3.Lerp(buttonStart + buttonMove, buttonStart, 1.0 * Time.deltaTime)
			door.position=Vector3.Lerp(doorStart + doorMove, doorStart, 2.0 * Time.deltaTime)
		}
	}
}

OnTriggerEnter(collider){
	if(collider.gameObject.tag="MyKey"){
		dobutton=true;
	}
}

OnTriggerExit(collider){
	if(collider.gameObject.tag="MyKey"){
		dobutton=false;
	}
}

If you don’t mind me asking, what resources do you recommend so that I can learn how to script this? As I have stated before, I do not know how.