35 lines
852 B
C#
35 lines
852 B
C#
using UnityEngine;
|
|
|
|
public class BlockDrop_BerryBomb : MonoBehaviour
|
|
{
|
|
public float speed = 18f;
|
|
public float life = 3f;
|
|
public Vector3 explosionSize = new Vector3(3f, 3f, 0.5f);
|
|
public LayerMask blockMask;
|
|
|
|
void Start() { Destroy(gameObject, life); }
|
|
|
|
void Update()
|
|
{
|
|
transform.position += transform.forward * speed * Time.deltaTime;
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
Explode();
|
|
}
|
|
|
|
void Explode()
|
|
{
|
|
Collider[] hits = Physics.OverlapBox(transform.position, explosionSize * 0.5f, Quaternion.identity, blockMask);
|
|
foreach (var c in hits)
|
|
{
|
|
if (c.TryGetComponent<BlockDrop_Block>(out var b))
|
|
{
|
|
if (b.type != BlockDrop_BlockType.Indestructible) b.Hit(10);
|
|
}
|
|
}
|
|
Destroy(gameObject);
|
|
}
|
|
}
|