Im trying to make fire spread but everytime it goes to clone it crashes
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class FireLogic : MonoBehaviour
{
[SerializeField] float health;
float spreadTimer;
float dieTimer;
GameObject clone;
Vector2 spawnPos;
public float spreadTime = 5;
public float minRange = -10;
public float maxRange = 10;
public float dieTime = 10;
public float maxHealth = 100;
public GameObject water;
public LayerMask flammable;
void Start()
{
health = maxHealth;
}
void Update()
{
spawnPos = new Vector2(gameObject.transform.position.x + Random.Range(minRange, maxRange) , gameObject.transform.position.y + Random.Range(minRange, maxRange));
spreadTimer += Time.deltaTime;
if(spreadTimer > spreadTime)
{
spreadTimer = 0;
print("spread");
clone = Instantiate(gameObject, spawnPos, transform.rotation);
while (clone.GetComponent().IsTouchingLayers(flammable))
{
Destroy(clone);
spawnPos = new Vector2(gameObject.transform.position.x + Random.Range(minRange, maxRange) , gameObject.transform.position.y + Random.Range(minRange, maxRange));
clone = Instantiate(gameObject, spawnPos, transform.rotation);
}
}
}
void WaterHit(float waterDamage)
{
health -= waterDamage;
if(health < 0) Destroy(gameObject);
}
}
↧