54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Attach this to your Player object and hit Play once to remove duplicate guns.
|
|
/// Delete this script after running it.
|
|
/// </summary>
|
|
public class RemoveDuplicateGuns : MonoBehaviour
|
|
{
|
|
void Start()
|
|
{
|
|
Debug.Log("=== SEARCHING FOR DUPLICATE GUNS ===");
|
|
|
|
// Find all SimpleGun components in children
|
|
SimpleGun[] guns = GetComponentsInChildren<SimpleGun>();
|
|
|
|
Debug.Log($"Found {guns.Length} gun(s)");
|
|
|
|
if (guns.Length <= 1)
|
|
{
|
|
Debug.Log("Only one gun found - no duplicates to remove");
|
|
return;
|
|
}
|
|
|
|
// Keep the gun that's furthest from the player's feet (highest Y position)
|
|
SimpleGun highestGun = guns[0];
|
|
float highestY = guns[0].transform.position.y;
|
|
|
|
foreach (SimpleGun gun in guns)
|
|
{
|
|
Vector3 worldPos = gun.transform.position;
|
|
Debug.Log($"Gun at {gun.gameObject.name}: World Position = {worldPos}");
|
|
|
|
if (worldPos.y > highestY)
|
|
{
|
|
highestGun = gun;
|
|
highestY = worldPos.y;
|
|
}
|
|
}
|
|
|
|
// Remove all guns except the highest one
|
|
foreach (SimpleGun gun in guns)
|
|
{
|
|
if (gun != highestGun)
|
|
{
|
|
Debug.LogWarning($"REMOVING duplicate gun: {gun.gameObject.name} at {gun.transform.position}");
|
|
Destroy(gun.gameObject);
|
|
}
|
|
}
|
|
|
|
Debug.Log($"Kept gun: {highestGun.gameObject.name} at {highestGun.transform.position}");
|
|
Debug.Log("=== DUPLICATE REMOVAL COMPLETE ===");
|
|
}
|
|
}
|