- Home /
3D inventory problem
Hey guys!
I'm still fairly new to Unity so please if you answer a question dumb yourself down ^^ thanks! :D
Anyways, I'm making a script for picking up items, then pulling them out in an 3D inventory and rotating the looked upon object.
Something like the old Alone in the Dark games and such - the idea is to have the item you are looking at in the middle of the screen and all other items you posses rotating by themselves in the bottom, then you scroll through the list and the selected item will pop up in the middle instead.. This is what I got so far:
Picking up an item:
if(Input.GetKeyDown("e")){
inventory[0] = hit.collider.gameObject.tag;
Destroy(hit.collider.gameObject);
}
Then to call the inventory I would clone objects infront of the player which has the tags that is in the inventory. And that works.. sorta, needs some tweaking, anyways! When the items pop up I turn off the mouselook and character motor scripts so the player stands still
I can rotate an item aswell, BUT then I want to close the inventory again, turning on stuff again and removing the items from the screen. Now I cant destroy just a clone, as that isnt an object per se, and as I am not looking at all the items with a raycast, say the one looked upon, I cannot remove it :O Please help me!
I was thinking about changing to another scene when opening the inventory, but then I would have to save and load constantly, which is stupid :P ...
Any advice please?
Here is the code when the inventory pops up:
if(Input.GetKeyDown("r") && inventoryOpen == false ){
inventoryOpen = true;
GameObject clone;
clone = Instantiate(Item, transform.position + transform.forward * 0.8f + transform.up, Quaternion.identity) as GameObject;
}
case "inventoryItem":
MouseLook mouseL = (MouseLook)gameObject.GetComponent(typeof(MouseLook));
mouseL.enabled = false;
CharacterMotor motor = (CharacterMotor)gameObject.GetComponent(typeof(CharacterMotor));
motor.canControl = false;
if(Input.GetButton("Fire1")){
hit.transform.Rotate(((Input.mousePosition.x - (Screen.width/2)) * Time.deltaTime), ((Input.mousePosition.y - (Screen.height/2))* Time.deltaTime), 0);
}
break;
and the code when Im trying to close the inventory
if(inventoryOpen == true){
if(Input.GetKeyDown("r")){
inventoryOpen = false;
MouseLook mouseL = (MouseLook)GetComponent(typeof(MouseLook));
mouseL.enabled = true;
CharacterMotor motor = (CharacterMotor)GetComponent(typeof(CharacterMotor));
motor.canControl = true;
Destroy(Interaction.hit.collider.gameObject);
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Object reference not set to an instance of an object 1 Answer