mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-04-10 21:47:07 +02:00
refactor: simplify instantiate prefabs (#41)
This commit is contained in:
parent
f305cd6c1f
commit
7fd8691033
@ -4,12 +4,12 @@
|
|||||||
"order": 2,
|
"order": 2,
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": 1,
|
"type": "Spike",
|
||||||
"x": -6.684000015258789,
|
"x": -6.684000015258789,
|
||||||
"y": -2.8970000743865969
|
"y": -2.8970000743865969
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": 1,
|
"type": "Spike",
|
||||||
"x": -3.059999942779541,
|
"x": -3.059999942779541,
|
||||||
"y": -2.930000066757202
|
"y": -2.930000066757202
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
"order": 1,
|
"order": 1,
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": 0,
|
"type": "Obstacle",
|
||||||
"x": -6.684000015258789,
|
"x": -6.684000015258789,
|
||||||
"y": -2.8970000743865969
|
"y": -2.8970000743865969
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": 1,
|
"type": "Spike",
|
||||||
"x": -3.059999942779541,
|
"x": -3.059999942779541,
|
||||||
"y": -2.930000066757202
|
"y": -2.930000066757202
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,7 @@ using System.Runtime.Serialization;
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class LevelElement
|
public class LevelElement
|
||||||
{
|
{
|
||||||
public enum Type
|
public string type;
|
||||||
{
|
|
||||||
Obstacle = 0,
|
|
||||||
Spike = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type type;
|
|
||||||
public float x;
|
public float x;
|
||||||
public float y;
|
public float y;
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,10 @@ public class LevelLoader : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public LevelsLoader levelsLoader;
|
public LevelsLoader levelsLoader;
|
||||||
public AudioSource audioSource;
|
public AudioSource audioSource;
|
||||||
public GameObject obstaclePrefab;
|
|
||||||
public GameObject spikePrefab;
|
|
||||||
public GameObject winnerWall;
|
|
||||||
|
|
||||||
private GameObject GetPrefab(LevelElement.Type type)
|
private GameObject GetPrefab(string type)
|
||||||
{
|
{
|
||||||
if (type == LevelElement.Type.Spike)
|
return Resources.Load<GameObject>("Prefabs/" + type);
|
||||||
{
|
|
||||||
return spikePrefab;
|
|
||||||
}
|
|
||||||
return obstaclePrefab;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadAudio()
|
private void LoadAudio()
|
||||||
@ -26,10 +19,6 @@ public class LevelLoader : MonoBehaviour
|
|||||||
|
|
||||||
private void LoadElements()
|
private void LoadElements()
|
||||||
{
|
{
|
||||||
obstaclePrefab = Resources.Load<GameObject>("Prefabs/Obstacle");
|
|
||||||
spikePrefab = Resources.Load<GameObject>("Prefabs/Spike");
|
|
||||||
winnerWall = Resources.Load<GameObject>("Prefabs/WinnerWall");
|
|
||||||
|
|
||||||
Level current = levelsLoader.levelCurrent;
|
Level current = levelsLoader.levelCurrent;
|
||||||
foreach (var element in current.elements)
|
foreach (var element in current.elements)
|
||||||
{
|
{
|
||||||
@ -43,7 +32,7 @@ public class LevelLoader : MonoBehaviour
|
|||||||
{
|
{
|
||||||
lastX += lastElement.x;
|
lastX += lastElement.x;
|
||||||
}
|
}
|
||||||
Instantiate(winnerWall, new Vector3(lastX, 0, 0), Quaternion.Euler(0, 0, 90));
|
Instantiate(GetPrefab("WinnerWall"), new Vector3(lastX, 0, 0), Quaternion.Euler(0, 0, 90));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user