mirror of
https://github.com/zoriya/ProtectFromTwitch.git
synced 2025-12-06 06:36:30 +00:00
30 lines
680 B
C#
30 lines
680 B
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class WallCollider : MonoBehaviour
|
|
{
|
|
public int hp = 2;
|
|
public int destroyTime = 5;
|
|
|
|
private void Start()
|
|
{
|
|
destroyTime -= GameObject.FindGameObjectsWithTag("Wall").Length;
|
|
destroyTime = Mathf.Clamp(destroyTime, 1, 5);
|
|
StartCoroutine("Unspawn");
|
|
}
|
|
|
|
private IEnumerator Unspawn()
|
|
{
|
|
yield return new WaitForSeconds(destroyTime);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
Destroy(collision.gameObject);
|
|
hp--;
|
|
Restarter.Score++;
|
|
if(hp == 0)
|
|
Destroy(gameObject);
|
|
}
|
|
} |