-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_PlatformTile.cs
More file actions
74 lines (65 loc) · 2.41 KB
/
_PlatformTile.cs
File metadata and controls
74 lines (65 loc) · 2.41 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class _PlatformTile : MonoBehaviour
{
public Transform startPoint;
public Transform endPoint;
public GameObject[] obstacles; //Objects that contains different obstacle types which will be randomly activated
public GameObject mathprob;
private float cubeSize = 0.3f;
private List<GameObject> spawnedCubes = new List<GameObject>(); // New List to store spawned cubes
public void ActivateRandomObstacle()
{
DeactivateAllObstacles();
ClearSpawnedCubes();
mathprob.GetComponent<RandomMathProblemGenerator>().GenerateRandomMathProblem();
int Canswer = mathprob.GetComponent<RandomMathProblemGenerator>().answer;
List<int> answerlist = mathprob.GetComponent<RandomMathProblemGenerator>().randomizedAnswers;
spawnedCubes.Clear();
for (int i = 0; i < answerlist.Count; i++)
{
if (answerlist[i] == Canswer)
{
Vector3 spawnPosition = new Vector3(-3f + 3 * i, -1f, 40f);
GameObject cube = CreateCube(spawnPosition, cubeSize);
cube.tag = "Untagged"; // Empty tag means no tag assigned
Destroy(cube.GetComponent<BoxCollider>()); // Remove Box Collider
spawnedCubes.Add(cube);
}
else
{
Vector3 spawnPosition = new Vector3(-3f + 3 * i, -1f, 40f);
GameObject cube = CreateCube(spawnPosition, cubeSize);
cube.tag = "Finish"; // Assign the "Finish" tag
spawnedCubes.Add(cube);
}
}
}
public void DeactivateAllObstacles()
{
for (int i = 0; i < obstacles.Length; i++)
{
obstacles[i].SetActive(false);
}
}
public List<GameObject> GetSpawnedCubes()
{
return spawnedCubes;
}
private GameObject CreateCube(Vector3 position, float size)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = position;
cube.transform.localScale = new Vector3(size, size, size);
return cube;
}
private void ClearSpawnedCubes()
{
foreach (GameObject cube in spawnedCubes)
{
Destroy(cube);
}
spawnedCubes.Clear();
}
}