File size: 1,554 Bytes
05c9ac2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using UnityEngine;
using Unity.MLAgentsExamples;
public class PyramidArea : Area
{
public GameObject pyramid;
public GameObject stonePyramid;
public GameObject[] spawnAreas;
public int numPyra;
public float range;
public void CreatePyramid(int numObjects, int spawnAreaIndex)
{
CreateObject(numObjects, pyramid, spawnAreaIndex);
}
public void CreateStonePyramid(int numObjects, int spawnAreaIndex)
{
CreateObject(numObjects, stonePyramid, spawnAreaIndex);
}
void CreateObject(int numObjects, GameObject desiredObject, int spawnAreaIndex)
{
for (var i = 0; i < numObjects; i++)
{
var newObject = Instantiate(desiredObject, Vector3.zero,
Quaternion.Euler(0f, 0f, 0f), transform);
PlaceObject(newObject, spawnAreaIndex);
}
}
public void PlaceObject(GameObject objectToPlace, int spawnAreaIndex)
{
var spawnTransform = spawnAreas[spawnAreaIndex].transform;
var xRange = spawnTransform.localScale.x / 2.1f;
var zRange = spawnTransform.localScale.z / 2.1f;
objectToPlace.transform.position = new Vector3(Random.Range(-xRange, xRange), 2f, Random.Range(-zRange, zRange))
+ spawnTransform.position;
}
public void CleanPyramidArea()
{
foreach (Transform child in transform)
if (child.CompareTag("pyramid"))
{
Destroy(child.gameObject);
}
}
public override void ResetArea()
{
}
}
|