RPG script

Can anyone help me in creating a script that would allow me the player to run to an object and pick it up? The player would collide with the object and add the object to inventory to its correct group.

Its like a basic RPG type game.

Thanks in advance.

Some of that depends on how you’re implementing your inventory. As a basic example, though, for a script that you’d apply to the controller:

var inventory : Array;

function Start () {
	inventory = new Array();
}

function OnTriggerEnter (other : Collider) {
	if (other.tag == "Item") {
		inventory.Push(other.name);
		Destroy(other.gameObject);
	}
}

function Update () {
	if (Input.GetKeyDown("i")) {
		print ("You have:");
		for (i in inventory) {print (i);}
	}
}

You’d make a new tag called “Item”, and apply that tag to any items you wanted to be able to pick up. You’d also make these items have colliders that are triggers.

That script just adds the name of any item you pick up to your inventory. For categories, that depends on what you’re doing exactly.

–Eric