Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Clearing Dynamically GameObject Array

$
0
0
**Hi,** well I created an array for my weapons, and when I change the selected slot of my Inventarory, I want to clear the last gameobject charged by the following code: bool slotChanged; int selectedSlot; //That changes float tempselectedSlot; int tempSelected; GameObject Manager; //A simple GameObject that contains a Store GameObject wCamera; //Another Script that contains PlayerWeapons PlayerWeapons pWeapons; void Start() { pWeapons = wCamera.GetComponent(); } void Update() { if (selectedSlot > 9) { //That supposedly avoids the array out of index error, but that doesn't avoid anything... Because sometimes that fails... tempselectedSlot = 0; } else if(selectedSlot < 0) { tempselectedSlot = 9; } tempselectedSlot -= Input.GetAxis("Mouse ScrollWheel")/2; //Mouse ScrollWheel is equals to 1. selectedSlot = (int)tempselectedSlot; slotChanged = selectedSlot != tempSelected; tempSelected = selectedSlot; if(slotChanged) { //If the selected Slot changes, that actives, and it supposedly clears the main weapon GameObject array, and if there is a new item in the selected slot, charges it... pWeapons.ClearArray(); //A JS Function that supposedly clears the main array. if(Slots.HotBarSlots[selectedSlot] != null) { //If the selected Slot contains a Element... Manager.transform.Find("StoreController").gameObject.GetComponent().equipWeapon(pAvoider.transform.Find(Slots.HotBarSlots[selectedSlot].itemname).gameObject.GetComponent(), 0); //That Calls the function equipWeapon, from Manager -> StoreController -> DBStoreController (JS Script) } } } equipWeapon works so I won't put the code... But ClearArray doesn't works, so there is the problem: //The problem is that it's in JS (because it's a very big third party code) function ClearArray() { var Dweapons = new Array(weapons); //Create a dinamically array from a builtin array Dweapons.Clear(); //Clear it entire Dweapons.length = 1; //Set the default length weapons = Dweapons; //And return a builtin array... } //But for some reason it desn't work, the GameObject is still there when there isn't a item on the selected slot... All is in the code comments, so read it, and tell me what I'm doing wrong... **Thanks in advance... Bye.**

Viewing all articles
Browse latest Browse all 7934

Trending Articles