public class C_Shell : MonoBehaviour
{
public GameObject shellObject;
public bool countdown;
public float deleteTime;
public Vector3 velocity;
public Vector3 position;
public C_Shell(GameObject _shellObject, float _deleteTime, bool _countdown, Vector3 _position, Vector3 _velocity)
{
this.shellObject = _shellObject;
this.countdown = _countdown;
this.deleteTime = _deleteTime;
this.position = _position;
this.velocity = _velocity;
}
public void SelfDestruct()
{
Destroy(this, this.deleteTime);
}
public void UpdateObject()
{
this.shellObject.transform.position = this.position;
}
}
public class Shell_Manager : MonoBehaviour
{
public static Shell_Manager instance;
public const int maxShells = 128;
public List<C_Shell> shells;
public float deleteTime = 3.0f;
private void Awake()
{
if (instance == null)
instance = this;
}
private void Start()
{
}
private void Update()
{
}
private void FixedUpdate()
{
UpdateShells();
}
private void UpdateShells()
{
int index = 0;
foreach (C_Shell shell in shells)
{
shell.SelfDestruct();
shell.countdown = true;
shell.position += shell.velocity * Time.fixedDeltaTime;
shell.position += Physics.gravity * Time.fixedDeltaTime;
index++;
}
}
public void FireShell(ShellFire _shell)
{
Vector3 initialPosition = _shell.initialPosition;
Quaternion initialAngle = _shell.initialAngle;
switch (_shell.eShellType)
{
case EShellType.AP:
{
Fire_AP(initialPosition, initialAngle);
break;
}
case EShellType.HE:
{
Fire_HE(initialPosition, initialAngle);
break;
}
}
}
void Fire_AP(Vector3 _initialPosition, Quaternion _initialAngle)
{
Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Resources/Prefabs/Shell.prefab", typeof(GameObject));
shells.Add(new C_Shell(Instantiate(prefab, _initialPosition, _initialAngle) as GameObject, deleteTime, false, _initialPosition, Vector3.forward * C_AP.constants.force));
}
void Fire_HE(Vector3 _initialPosition, Quaternion _initialAngle)
{
Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Resources/Prefabs/Shell.prefab", typeof(GameObject));
shells.Add(new C_Shell(Instantiate(prefab, _initialPosition, _initialAngle) as GameObject, deleteTime, false, _initialPosition, Vector3.forward * C_HE.constants.force));
}
}
I dont know why is C_Shell object not being destroyed