// Repair robot on trigger or over a certain duration private void OnTriggerEnter(Collider other) { _hp = other.GetComponent <HitPoints>(); if (_hp == null) { return; } if (_canRepair == false) { return; } _canRepair = false; GameObject particles = Instantiate(_repairParticles, other.transform.position, _repairParticles.transform.rotation, other.transform); Destroy(particles, _particleLifetime); if (_repairSound != null) { _repairSound.Play(); } if (_isRepairOverTime == false) { _hp.AddHitPoints(_repairAmount); Destroy(gameObject); } else { GetComponent <MeshRenderer>().enabled = false; _repairStarted = true; } }
// ================================== REPAIR ==================================== private void RepairOverTime() { if (_repairCounter < _repairDuration) { _repairCounter += Time.deltaTime; _hp.AddHitPoints((Time.deltaTime / _repairDuration) * _repairAmount); } else { Destroy(gameObject); } }