added gun models and enemy spawner
This commit is contained in:
53
Assets/Scripts/RemoveDuplicateGuns.cs
Normal file
53
Assets/Scripts/RemoveDuplicateGuns.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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 ===");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user