Quantcast
Channel: Latest Questions by GWJustin
Viewing all articles
Browse latest Browse all 6

Placing a gameObject into, and pulling out of inventory

$
0
0
I'd really appreciate some help with what shouldn't be a very difficult concept. In my game when I right click gameObjects of a certain type (in my case I've created a custom class called InventoryObject) the object is added to the inventory. That's no problem. It's what happens to the gameObject in my scene that is tripping me up. My initial thought was to just "hide" it basically - turn off all it's colliders, make the rigidbody kinematic, and disable the renderer. Well this concept is giving me issues. I managed to disable the colliders like so: internal var _isColliderEnabled:boolean = true; function get isColliderEnabled():boolean { return _isColliderEnabled; } function set isColliderEnabled(value:boolean):void { _isColliderEnabled = value; //get all colliders in the object var colliders:Component[] = this.gameObject.GetComponentsInChildren(Collider); var collider:Collider; for(var i:int = 0;i < colliders.length; i++) { collider = colliders[i].collider; //collider.enabled = !value; collider.isTrigger = !value; //print(i+") "+collider.gameObject); } } (sorry, this window seems like it's totally screwing up my tabbing and code formatting) Anyhow, then I turn off the rigidbody something like this: this.rigidbody.isKinematic = !value; My next step is to make the gameObject invisible. So I try to find the renderer in the game object and disable it. Well, for some reason there doesn't happen to be any renderer in my gameObjects. I can however find a MeshRenderer like this: var itemRenderer:MeshRenderer = item.transform.root.gameObject.GetComponentInChildren(MeshRenderer); Then I try to disable it: itemRenderer.enabled = false; Well, it's not working. My objects are still visible. So, now I'm thinking of shifting gears and destroying the object when I place it in the inventory, and reinstantiating it when taking it out. Can anyone offer some good insight into the best way of going about the task of placing a gameObject into, and pulling out of inventory? Much appreciated.

Viewing all articles
Browse latest Browse all 6

Trending Articles