Obstacles According to difficulties

main
Ali Sharoz 2 months ago
parent 7ac0cfaf4a
commit 0a9a8da387

@ -79,5 +79,5 @@ Material:
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []

@ -40,6 +40,8 @@ public class BuildingParent : MonoBehaviour
[ContextMenu("Func")] [ContextMenu("Func")]
public void Func() public void Func()
{ {
//if (InstantiatedObstacle != null)
// Destroy(InstantiatedObstacle);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
Building temp = Instantiate(buildingObj, transform); Building temp = Instantiate(buildingObj, transform);
@ -55,7 +57,7 @@ public class BuildingParent : MonoBehaviour
temp.renderers[j].material = Buildingmaterials[rand]; temp.renderers[j].material = Buildingmaterials[rand];
} }
} }
if (percentAgeObstacle < 30) if (percentAgeObstacle < 80)
{ {
InstantiatedObstacle = Instantiate(obstacleObj, temp.transform); InstantiatedObstacle = Instantiate(obstacleObj, temp.transform);
} }
@ -68,9 +70,10 @@ public class BuildingParent : MonoBehaviour
int temp = counter % BuildingPool.Count; int temp = counter % BuildingPool.Count;
BuildingPool[temp].transform.localPosition = new Vector3(0, 0, -100 - (10 * counter)); BuildingPool[temp].transform.localPosition = new Vector3(0, 0, -100 - (10 * counter));
counter++; counter++;
Destroy(InstantiatedObstacle); if (InstantiatedObstacle != null)
Destroy(InstantiatedObstacle.gameObject);
int percentAgeObstacle = Random.Range(0, 100); int percentAgeObstacle = Random.Range(0, 100);
if (percentAgeObstacle < 20) if (percentAgeObstacle < 80)
InstantiatedObstacle = Instantiate(obstacleObj, BuildingPool[temp].transform); InstantiatedObstacle = Instantiate(obstacleObj, BuildingPool[temp].transform);
int percentAge = Random.Range(0, 100); int percentAge = Random.Range(0, 100);

@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum DifficultyLevel
{
easy, medium, hard,
}
public class GameManager : MonoBehaviour
{
public DifficultyLevel difficultyLevel;
public List<int> difficultyScores;
public float Score;
public static GameManager instance;
public bool isGameOver = false;
public void Awake()
{
instance = this;
}
private void Start()
{
StartCoroutine(ScoreUpdateRoutine());
}
IEnumerator ScoreUpdateRoutine()
{
difficultyLevel = DifficultyLevel.easy;
while (!isGameOver)
{
Score++;
UIManager.instance.ScoreText.text = Score.ToString();
if(Score > difficultyScores[(int)difficultyLevel] && (int)difficultyLevel< difficultyScores.Count-1)
{
difficultyLevel++;
}
Debug.Log("difficulty Level: " + (int)difficultyLevel);
yield return new WaitForSeconds(1);
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e82af5507a3f3745885b4e14a26d858
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -78,6 +78,6 @@ Material:
- _UVSec: 0 - _UVSec: 0
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 0.11969948, g: 1, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []

@ -4,14 +4,36 @@ using UnityEngine;
public class Obstacle : MonoBehaviour public class Obstacle : MonoBehaviour
{ {
public List<GameObject> obstacleObjs; public List<GameObject> easyObstacleObjs;
public List<GameObject> mediumObstacleObjs;
public List<GameObject> hardObstacleObjs;
private void Start() private void Start()
{ {
Starter(); Starter();
} }
public void Starter() public void Starter()
{ {
int rand=Random.Range(0, obstacleObjs.Count); List<GameObject> list = DifficultyList();
obstacleObjs[rand].gameObject.SetActive(true); Debug.Log("list: " + list[list.Count-1].name);
int rand = Random.Range(0, list.Count);
list[rand].gameObject.SetActive(true);
}
List<GameObject> DifficultyList()
{
int difficultyLevel = (int)GameManager.instance.difficultyLevel;
return difficultyLevel == 0 ? easyObstacleObjs : difficultyLevel == 1 ? mediumObstacleObjs : hardObstacleObjs;
//if (difficultyLevel == 0)
//{
// return easyObstacleObjs;
//}
//else if (difficultyLevel == 1)
//{
// return mediumObstacleObjs;
//}
//else
//{
// return HardObstacleObjs;
//}
} }
} }

File diff suppressed because it is too large Load Diff

@ -1271,6 +1271,54 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &807834275
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 807834277}
- component: {fileID: 807834276}
m_Layer: 0
m_Name: GameManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &807834276
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 807834275}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7e82af5507a3f3745885b4e14a26d858, type: 3}
m_Name:
m_EditorClassIdentifier:
difficultyLevel: 0
difficultyScores: 050000000a0000000f000000
Score: 0
isGameOver: 0
--- !u!4 &807834277
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 807834275}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.46505004, y: 23.937662, z: 0.49310187}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &811116566 --- !u!1 &811116566
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -5159,3 +5207,4 @@ SceneRoots:
- {fileID: 811116571} - {fileID: 811116571}
- {fileID: 391446497} - {fileID: 391446497}
- {fileID: 1442169893} - {fileID: 1442169893}
- {fileID: 807834277}

@ -10,8 +10,6 @@ public class UIManager : MonoBehaviour
public CharacterController player; public CharacterController player;
public GameObject GameOverPanel; public GameObject GameOverPanel;
public CameraFollow cameraFollow; public CameraFollow cameraFollow;
bool isGameOver = false;
float Score;
public TextMeshProUGUI ScoreText; public TextMeshProUGUI ScoreText;
private void Awake() private void Awake()
{ {
@ -20,21 +18,11 @@ public class UIManager : MonoBehaviour
private void Start() private void Start()
{ {
UpdateHealth(); UpdateHealth();
StartCoroutine(ScoreUpdateRoutine());
}
IEnumerator ScoreUpdateRoutine()
{
while(!isGameOver)
{
Score += Time.fixedDeltaTime;
ScoreText.text = Mathf.FloorToInt(Score).ToString();
yield return new WaitForSeconds(Time.fixedDeltaTime);
}
} }
public void UpdateHealth() public void UpdateHealth()
{ {
if (!isGameOver) if (!GameManager.instance.isGameOver)
{ {
if (player.Health <= 0) if (player.Health <= 0)
{ {
@ -50,7 +38,7 @@ public class UIManager : MonoBehaviour
} }
void GameOver() void GameOver()
{ {
isGameOver = true; GameManager.instance.isGameOver = true;
Destroy(player.SpineHingeJoint); Destroy(player.SpineHingeJoint);
GameOverPanel.SetActive(true); GameOverPanel.SetActive(true);
cameraFollow.isPlaying = false; cameraFollow.isPlaying = false;

Loading…
Cancel
Save