Pickup Scripting?

Does anyone have basic knowledge on how to create a basic script for picking any object up?

Does the object need to be specific, or can one script govern over all desired pickups?

I’m trying to gather objects while flying through the air… I recently got my flying working but now I need a little more flavor for my game!

Thanks

Do you mean pickup as in pick up and hold in your hands/attach to the character, or pickup as in “run over this object, it disappears and you get a temporary/permanent bonus”?

pickup as in run over and it disappears and you get a bonus!!!

thanks

Look into triggers. Place a trigger on your pickup object and script it accordingly. Something like:

var pointsGiven : int = 10;

OnTriggerEnter(coll : Collider){

if (coll.gameobject.tag == “Player”){

coll.gameobject.SendMessage(“IncreasePoints”, pointsGiven);
Destroy(gameObject);
}

}

So I gathered this so far, and I applied it to a block in front of my flying cube.

I named the cube Player in the hierarchy, and this is not functioning… I fly right through the block. Do I need to call this in the Update function?

Thanks

function OnTriggerEnter(coll : Collider)
{
	if (coll.gameObject.tag == "Player")
	{
		coll.gameObject.SendMessage("HECK YEAH");
		Destroy(gameObject);
	}
}

function Update () {
}

figured it out… it’s .name not .tag

thanks for all the help!

Well yes, I was referencing to the tag which you can give game objects :slight_smile: (Say, you make it multiplayer you would want to use tags instead of name).

Happy I could help, good luck onwards!