I need a two slot inventory in my game but I’m not that sure about how I am supposed to do it. I basically have 2 empty variables named slot1 and slot2. The plan is that if you press E while you’re in the area of the gameObject (the area is just an invisible isTrigger sphere), it gets added to your inventory as slot1. But I am not that sure how I would make that adding work. Here is my script that I wrote (I haven’t made anything for slot2 yet on purpose):
var slot1 : Transform;
var slot2 : Transform;
function Update () {
}
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Enemy") {
slot1 = other.gameObject.Transform;
}
}
function OnTriggerExit (other : Collider) {
if (other.gameObject.transform == slot1) {
slot1 = null;
}
}
Please explain how your editing of my script works so i can improve my scripting in the future.
PS: Please write the script in javascript.