59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
class MinionRespowner : MonoBehaviour
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Function to determine if object nad respown object
|
|||
|
/// </summary>
|
|||
|
public bool Blocked = false;
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public void Respown(GameObject enemyModel)
|
|||
|
{
|
|||
|
// Change position
|
|||
|
var newPosition = new Vector3(
|
|||
|
gameObject.transform.position.x + UnityEngine.Random.Range(-3.8f, 3.8f),
|
|||
|
gameObject.transform.position.y + UnityEngine.Random.Range(-3.8f, 3.8f),
|
|||
|
10
|
|||
|
);
|
|||
|
|
|||
|
BuildMinion(enemyModel, newPosition);
|
|||
|
}
|
|||
|
|
|||
|
public void BuildMinion(GameObject minion, Vector3 coord)
|
|||
|
{
|
|||
|
var sceneGui = GameObject.FindGameObjectWithTag("EnemyCollection");
|
|||
|
|
|||
|
if (sceneGui == null)
|
|||
|
{
|
|||
|
throw new Exception("GUI not found on scene!!!");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var newMinion = Instantiate(minion, coord, Quaternion.identity, sceneGui.transform);
|
|||
|
|
|||
|
newMinion.name = minion.name;
|
|||
|
// newMinion.transform.SetParent(sceneGui.transform);
|
|||
|
|
|||
|
newMinion.GetComponent<SpriteRenderer>().sortingOrder = 3;
|
|||
|
|
|||
|
newMinion.AddComponent<RespownTrigger>();
|
|||
|
newMinion.GetComponent<RespownTrigger>().SetParentRespowner(GameObject.FindObjectOfType<CounterRespowner>().gameObject);
|
|||
|
|
|||
|
}
|
|||
|
}
|