initial commit
This commit is contained in:
97
Assets/Scripts/Lesson_1/RunlinePlacer.cs
Normal file
97
Assets/Scripts/Lesson_1/RunlinePlacer.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RunlinePlacer : MonoBehaviour
|
||||
{
|
||||
[Header("Runway Properties")]
|
||||
public float radiusX = 105f;
|
||||
public float radiusZ = 55f;
|
||||
public Vector3 center;
|
||||
public List<Transform> linePositions = new List<Transform>();
|
||||
public GameObject startLinePrefab;
|
||||
public GameObject endLinePrefab;
|
||||
public AmyRunScript amy;
|
||||
|
||||
private float largeTurnOffset = 50f;
|
||||
private GameObject activeStartLine;
|
||||
private GameObject activeEndLine;
|
||||
|
||||
private DrawDistanceLine drawDistanceLine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
center = transform.position;
|
||||
drawDistanceLine = GetComponent<DrawDistanceLine>();
|
||||
}
|
||||
|
||||
[ContextMenu("Respawn lines")]
|
||||
public void RuntimePlace()
|
||||
{
|
||||
drawDistanceLine.ClearArc();
|
||||
foreach (Transform t in linePositions)
|
||||
{
|
||||
foreach (Transform child in t)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
int firstPositionIndex = Random.Range(0, 4);
|
||||
int secondPositionIndex;
|
||||
do
|
||||
{
|
||||
secondPositionIndex = Random.Range(0, 4);
|
||||
} while (secondPositionIndex == firstPositionIndex);
|
||||
|
||||
PlaceLine(firstPositionIndex, startLinePrefab, true);
|
||||
PlaceLine(secondPositionIndex, endLinePrefab);
|
||||
|
||||
amy.PlaceOnStartAngle();
|
||||
// Experiment 2
|
||||
if (Lesson1Controller.Instance.activeExperiment == 2) drawDistanceLine.DrawDistanceArc();
|
||||
}
|
||||
|
||||
private void PlaceLine(int positionIndex, GameObject prefabIfSmall, bool isStart = false)
|
||||
{
|
||||
GameObject instantiatedLine = Instantiate(prefabIfSmall);
|
||||
instantiatedLine.transform.SetParent(linePositions[positionIndex]);
|
||||
instantiatedLine.transform.localPosition = Vector3.zero;
|
||||
instantiatedLine.transform.localRotation = Quaternion.identity;
|
||||
if (positionIndex > 1)
|
||||
{
|
||||
Vector3 pos = instantiatedLine.transform.localPosition;
|
||||
pos.x = Random.Range(-largeTurnOffset, largeTurnOffset);
|
||||
instantiatedLine.transform.localPosition = pos;
|
||||
}
|
||||
|
||||
LineData ilinedata = instantiatedLine.GetComponent<LineData>();
|
||||
|
||||
ilinedata.FindCurrentAngle(radiusX, radiusZ);
|
||||
|
||||
if (isStart)
|
||||
{
|
||||
amy.SetAngle(ilinedata.angle);
|
||||
amy.startAngle = ilinedata.angle;
|
||||
activeStartLine = instantiatedLine;
|
||||
} else
|
||||
{
|
||||
activeEndLine = instantiatedLine;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetStartLineAngle()
|
||||
{
|
||||
LineData ilinedata = activeStartLine.GetComponent<LineData>();
|
||||
return ilinedata.angle;
|
||||
}
|
||||
|
||||
public float GetEndLineAngle()
|
||||
{
|
||||
LineData ilinedata = activeEndLine.GetComponent<LineData>();
|
||||
return ilinedata.angle;
|
||||
}
|
||||
public GameObject GetStartLineGameObject()
|
||||
{
|
||||
return activeStartLine;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user