2020-06-28 19:12:59 -04:00

26 lines
770 B
C#

using System;
using UnityEngine;
public class Arena : MonoBehaviour {
public MapData data;
public GameObject explosionPrefab;
public void Explode(Vector3 position, int strength) {
if (strength <= 0)
throw new ArgumentException("Explosion strength must be positive.");
Vector3 explosionPos = data.GetClosestTilePos(position);
for (int i = 0; i < 3; i++) {
var rotation = explosionPrefab.transform.rotation;
var newRotation = Quaternion.Euler(rotation.eulerAngles + Vector3.up * i * 60f);
var explosion = Instantiate(explosionPrefab, explosionPos, newRotation);
//TODO multiply explosion.transform.scale.y by strength
Destroy(explosion, 1f);
}
}
public Vector3 GetClosestTilePos(Vector3 pos) => data.GetClosestTilePos(pos);
}