public void TryDropWeapon() //"dropar" arma aleatoriamente, inimigo { GameObject newWeaponDrop = PickRandomWeapon(); //pega arma que vai dropar / prefab if (newWeaponDrop == null) { Debug.Log(gameObject.name + " --> Nao dropou nada / problema no drop."); return; } string newWeaponDropColor = PickRandomColor(); //pega cor da arma que vai dropar GameObject newDroppedWeapon = Instantiate(weaponBasePrefab, gameObject.transform.position, gameObject.transform.rotation); //"dropar" arma que estava segurando newDroppedWeapon.name = "Map:-> " + weaponBasePrefab.name; //refatorar nome GameObject newDroppedWeaponChild = newDroppedWeapon.transform.GetChild(0).gameObject; //pegar "arma" dropada WeaponControllerPickUp pickUpScript = newDroppedWeaponChild.GetComponent <WeaponControllerPickUp>(); //pegar script para setar valores pickUpScript.player = player; pickUpScript.weaponHere = newWeaponDrop; //criar arma no chao pickUpScript.weaponHereColor = newWeaponDropColor; //pegar / setar cor (para ativar) Debug.Log(gameObject.name + ": Drop --> " + newWeaponDrop.name + "_" + newWeaponDropColor); //fala qual arma dropou / deveria dropar }
public void DropCurrentWeapon() //dropar arma corrente do player { GameObject newDroppedWeapon = Instantiate(weaponBasePrefab, gameObject.transform.position, gameObject.transform.rotation); //"dropar" arma que estava segurando newDroppedWeapon.name = "Map:-> " + weaponBasePrefab.name; //refatorar nome //GameObject newPrefabFound = (GameObject)Resources.Load("../Prefabs/PlayerGuns/" + playerWeapon.name, typeof(GameObject)); // encontrar prefab da arma //user pasta resources GameObject newPrefabFound = FindPrefab(playerWeapon.name); //encontra prefab da arma no vetor de disponiveis GameObject newDroppedWeaponChild = newDroppedWeapon.transform.GetChild(0).gameObject; //pegar "arma" dropada WeaponControllerPickUp pickUpScript = newDroppedWeaponChild.GetComponent <WeaponControllerPickUp>(); //pegar script para setar valores pickUpScript.player = player; if (newPrefabFound == null) //se nao encontrar { Debug.Log("A problem occurred while trying to find the dropped prefab: " + playerWeapon.name); return; } pickUpScript.weaponHere = newPrefabFound; //trocar arma pickUpScript.weaponHereColor = ChooseColorDrop(); //trocar cor }