protected override void Cleanup() { chargedTime_ = 0.0f; chargingLaserContainer_.transform.RecycleAllChildren(); chargingLaser_ = null; fullyChargedParticle_ = null; }
private void Update() { if (!Enabled) { UpdateWeightModification(); return; } if (!InputDelegate_.LaserPressed && chargedTime_ >= kChargeTime) { ShootLaser(); chargedTime_ = 0.0f; } float previousPercentCharged = chargedTime_ / kChargeTime; if (InputDelegate_.LaserPressed && InGameConstants.IsAllowedToChargeLasers(Player_)) { chargedTime_ += Time.deltaTime * kChargeRate; } else { chargedTime_ -= Time.deltaTime * kDischargeRate; } chargedTime_ = Mathf.Clamp(chargedTime_, 0.0f, kChargeTime); float percentCharged = chargedTime_ / kChargeTime; if (percentCharged <= 0.0f && chargingLaser_ != null) { ObjectPoolManager.Recycle(chargingLaser_); chargingLaser_ = null; } else if (percentCharged > 0.0f && chargingLaser_ == null) { chargingLaser_ = ObjectPoolManager.Create <ChargingLaser>(chargingLaserPrefab_, parent: chargingLaserContainer_); chargingLaser_.SetColor(Player_.Skin.LaserColor, Player_.Skin.SmearedLaserMaterial); } if (percentCharged < 1.0f && fullyChargedParticle_ != null) { DisperseFullyChargedParticle(); } if (chargingLaser_ != null) { chargingLaser_.UpdateWithPercentage(percentCharged); if (!Mathf.Approximately(previousPercentCharged, 1.0f) && Mathf.Approximately(percentCharged, 1.0f)) { fullyChargedParticle_ = ObjectPoolManager.Create <FullyChargedParticle>(fullyChargedParticlePrefab_, parent: chargingLaserContainer_); fullyChargedParticle_.SetColor(Player_.Skin.LaserColor); OnFullyCharged.Invoke(Player_); OnFullCharge.Invoke(); } } UpdateWeightModification(); }