using ShotSimulator.Tool; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace ShotSimulator.Target { public class MozambiqueHumanoidShotTarget : HumanoidShotTarget { public List m_NeedOrder = new List(); public List hitParts = new List(); private int next_MozambiqueIndex; public int currentHitIndex; public bool isCurFalseHit; public GameObject brokenFragment; public void InitMozambiqueHumanoidShotTarget() { next_MozambiqueIndex = 0; currentHitIndex = 0; hitParts.Clear(); //SetCurrentView(); gameObject.transform.LookAt(Camera.main.transform); } public override void CauseHumanoidPartReduceHP(HumanoidPartShotTarget part) { if (m_NeedOrder[next_MozambiqueIndex] == part.PartType&& !hitParts.Contains(part)) { hitParts.Add(part); switch (part.PartType) { case HumanoidPartType.Head: Health = 0f; break; case HumanoidPartType.Body: Health--; break; } part.SetColor(Color.red); m_NeedOrder.Add(part.PartType); currentHitIndex = next_MozambiqueIndex; next_MozambiqueIndex++; //SetCurrentView(); isCurFalseHit = false; } else { isCurFalseHit = true; } } private void SetCurrentView() { if (next_MozambiqueIndex < m_HumanoidParts.Count) { Text text = m_HumanoidParts[next_MozambiqueIndex].transform.Find("Canvas/OrderText").GetComponent(); text.gameObject.SetActive(true); text.text = (next_MozambiqueIndex + 1).ToString(); Vector3 m_IndexTextPos = m_HumanoidParts[next_MozambiqueIndex].transform.position; } } private void OnDestroy() { if (Health <= 0) { GameObject effectObj = Instantiate(Resources.Load("Prefabs/BrokenEffect"), transform.position + new Vector3(0, 2f, 0), Quaternion.identity); effectObj.transform.localScale = Vector3.one * 2; SpawnDebris(); } } private void SpawnDebris() { brokenFragment.transform.SetParent(null); brokenFragment.SetActive(true); foreach(Transform child in brokenFragment.transform) { // 随机选择碎片预制体 GameObject selectedDebris = child.gameObject; // 生成参数设置 Vector3 spawnPos = transform.position + Random.insideUnitSphere * 0.5f; Quaternion spawnRot = Random.rotation; selectedDebris.transform.position = spawnPos; selectedDebris.transform.rotation = spawnRot; // 添加物理组件 Rigidbody rb = selectedDebris.GetComponent(); if (rb == null) rb = selectedDebris.AddComponent(); // 施加随机方向力 Vector3 randomDir = new Vector3(Random.Range(-1f, 1f), Random.Range(0.5f, 1f), Random.Range(-1f, 1f)).normalized; float force = Random.Range(5f, 15f); rb.AddForce(randomDir * force, ForceMode.Impulse); // 添加随机旋转 rb.AddTorque(Random.insideUnitSphere * 50f, ForceMode.Impulse); } Destroy(brokenFragment, 0.5f); } } }