private void shoot(DeviceBase device, DeviceShotController controller) { if (controller.ammunitionQty > 0 && controller.waitTime <= 0) { // Update controllers controller.waitTime = device.reloadTime; controller.ammunitionQty--; // Create new instance GameObject createdDevice = Instantiate(device.gameObject); // Configure createdDevice.SetActive(true); createdDevice.transform.position = this.transform.position + (this.transform.right.normalized * device.distanceFromPlayer); createdDevice.transform.right = this.transform.right; DeviceBase aux = createdDevice.GetComponent <DeviceBase>(); if (aux) { aux.owner = this.gameObject; } controller.lastShot = createdDevice; // Set to right parent createdDevice.transform.parent = aux != null && aux.attachToPlayer ? this.transform : this.transform.parent; } }
void Update() { if (!properties.isCrashed) { for (int i = 0; i < devices.Length; i++) { var device = devices[i]; if (device && references.ContainsKey(device)) { DeviceShotController controller = references[device]; controller.waitTime -= Time.deltaTime; if (Input.GetButton("Fire" + (i + 1))) { shoot(device, controller); } } } } }