using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class SceneBlockContainer : MonoBehaviour { public enum Targets { Free, Go, Attack, Defence, Num };// Num is use for get total target bumber public float sceneSize = 10f; public GameObject EnvironmentObj; public GameObject[] attackBlockPrefabs = new GameObject[1]; public GameObject[] goBlockPrefabs = new GameObject[1]; public GameObject[] defencePrefabs = new GameObject[1]; private GameObject thisBlockObj; public SceneBlock thisBlock; private void Start() { } // create block random public void createNewBlock(Targets targetType, int blockType, Vector3 blockPosition,string tag1 = "Player", string tag2 = "Enemy") { // check if thisBlock is deleted if (thisBlockObj != null) { // delete thisBlock Debug.LogWarning("Block not clear!"); destroyBlock(); } // choose target type switch (targetType) { case Targets.Go: // goto thisBlockObj = Instantiate(goBlockPrefabs[blockType], blockPosition + EnvironmentObj.transform.position, Quaternion.identity, transform); thisBlock = thisBlockObj.GetComponent(); thisBlock.group1Tag = tag1; thisBlock.group2Tag = tag2; sceneSize = thisBlock.blockSize; break; case Targets.Attack: // attack thisBlockObj = Instantiate(attackBlockPrefabs[blockType], blockPosition+ EnvironmentObj.transform.position, Quaternion.identity, transform); thisBlock = thisBlockObj.GetComponent(); thisBlock.group1Tag = tag1; thisBlock.group2Tag = tag2; sceneSize = thisBlock.blockSize; break; case Targets.Defence: // defence thisBlockObj = Instantiate(defencePrefabs[blockType], blockPosition + EnvironmentObj.transform.position, Quaternion.identity, transform); thisBlock = thisBlockObj.GetComponent(); thisBlock.group1Tag = tag1; thisBlock.group2Tag = tag2; sceneSize = thisBlock.blockSize; break; } } // delete thisBlock public void destroyBlock() { if (thisBlock != null) { thisBlock.destroyMe(); } thisBlockObj = null; thisBlock = null; } public (float, int) getAgentTargetDistanceAndInside(Vector3 agentPosition) { return thisBlock.getDist_inArea(agentPosition); } }