public void OnDrill(Vector3 position, SeaMoth seamoth, out GameObject hitObject) { float num = 0f; for (int i = 0; i < drillable.health.Length; i++) { num += drillable.health[i]; } drillingMoth = seamoth; Vector3 zero = Vector3.zero; int num2 = FindClosestMesh(position, out zero); hitObject = renderers[num2].gameObject; timeLastDrilled = Time.time; if (num > 0f) { float num3 = drillable.health[num2]; drillable.health[num2] = Mathf.Max(0f, drillable.health[num2] - 5f); num -= num3 - drillable.health[num2]; if (num3 > 0f && drillable.health[num2] <= 0f) { renderers[num2].gameObject.SetActive(false); SpawnFX(drillable.breakFX, zero); if (Random.value < drillable.kChanceToSpawnResources) { SpawnLoot(zero); } } if (num <= 0f) { SpawnFX(drillable.breakAllFX, zero); onDrilled?.Invoke(drillable); if (drillable.deleteWhenDrilled) { float time = (!drillable.lootPinataOnSpawn) ? 0f : 6f; drillable.Invoke("DestroySelf", time); } } } }
public void Drill(Vector3 position, Shark shark, out GameObject hitObj) { float totalhp = 0f; foreach (float hp in drill.health) { totalhp += hp; } drillingShark = shark; int meshindex = drill.FindClosestMesh(position, out Vector3 zero); hitObj = drill.renderers[meshindex].gameObject; drill.timeLastDrilled = Time.time; if (totalhp > 0) { float meshhealth = drill.health[meshindex]; drill.health[meshindex] = Mathf.Max(0f, drill.health[meshindex] - 5f); totalhp -= meshhealth - drill.health[meshindex]; if (meshhealth > 0f && drill.health[meshindex] <= 0f) { drill.renderers[meshindex].gameObject.SetActive(false); drill.SpawnFX(drill.breakFX, zero); if (UnityEngine.Random.value < drill.kChanceToSpawnResources) { drill.SpawnLoot(zero); } } if (totalhp <= 0f) { drill.SpawnFX(drill.breakAllFX, zero); if (typeof(Drillable).GetField("onDrilled").GetValue(drill) is Drillable.OnDrilled onDrilled) { onDrilled(drill); } if (drill.deleteWhenDrilled) { float time = drill.lootPinataOnSpawn ? 6f : 0f; drill.Invoke("DestroySelf", time); } } } BehaviourUpdateUtils.Register(this); }
public void OnDrill(Vector3 position, SeaTruckHelper helper, out GameObject hitObject) { float num = 0f; for (int i = 0; i < drillable.health.Length; i++) { num += drillable.health[i]; } this.helper = helper; Vector3 zero = Vector3.zero; int num2 = FindClosestMesh(position, out zero); hitObject = renderers[num2].gameObject; timeLastDrilled = Time.time; if (num > 0f) { float num3 = drillable.health[num2]; drillable.health[num2] = Mathf.Max(0f, drillable.health[num2] - 5f); num -= num3 - drillable.health[num2]; if (num3 > 0f && drillable.health[num2] <= 0f) { renderers[num2].gameObject.SetActive(false); SpawnFX(drillable.breakFX, zero); if (drillable.resources.Length != 0) { StartCoroutine(SpawnLootAsync(zero)); } } if (num <= 0f) { SpawnFX(drillable.breakAllFX, zero); onDrilled?.Invoke(drillable); if (drillable.deleteWhenDrilled) { ResourceTracker component = GetComponent <ResourceTracker>(); if (component) { component.OnBreakResource(); } float time = (!drillable.lootPinataOnSpawn) ? 0f : 6f; drillable.Invoke("DestroySelf", time); } } } BehaviourUpdateUtils.Register(this); }