VladimirPirozhenko 4fa18a41a0 Changed animation strings to hashes, added IPoolable interface, upgrade pool system
Change generation of obstacles
Now all the important objects is cointained by pools
2022-08-09 22:23:49 +03:00

60 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
interface IObstacle
{
public void Impact();
}
[RequireComponent(typeof(BoxCollider))]
public class Obstacle : MonoBehaviour,IObstacle,IDamageDealer,IResettable,IPoolable<Obstacle>
{
public BoxCollider Collider { get; private set; }
public BasePool<Obstacle> OwningPool { private get; set; }
private void Awake()
{
Collider = GetComponent<BoxCollider>();
}
public void ResetToDefault()
{
transform.localPosition = Vector3.zero;
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
gameObject.transform.SetParent(OwningPool.transform);
ReturnToPool();
}
public void Impact()
{
ResetToDefault();
}
public void DealDamage(IDamageable target, int amount)
{
target.TakeDamage(amount);
}
public void ReturnToPool()
{
OwningPool.ReturnToPool(this);
}
}
public class Turret : MonoBehaviour, IObstacle, IDamageDealer, IResettable
{
public void DealDamage(IDamageable target, int amount)
{
target.TakeDamage(amount);
}
public void Impact()
{
gameObject.SetActive(true);
}
public void ResetToDefault()
{
gameObject.SetActive(true);
}
}