Add basic tutorial
This commit is contained in:
@@ -9,6 +9,10 @@ public class HouseManager : MonoBehaviour
|
||||
private float currentTtnw = 0;
|
||||
private int workerPerHouse = 3;
|
||||
private GameManager gameManager;
|
||||
|
||||
//House cost: Brick Tile Glass
|
||||
public int[] cost = new int[3] { 10, 5, 2 };
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@@ -36,17 +40,17 @@ public class HouseManager : MonoBehaviour
|
||||
|
||||
public void BuildHouse()
|
||||
{
|
||||
if (gameManager.GetResourceCount(Resource.BRICK) < 10 ||
|
||||
gameManager.GetResourceCount(Resource.TILE) < 5 ||
|
||||
gameManager.GetResourceCount(Resource.GLASS) < 2)
|
||||
if (gameManager.GetResourceCount(Resource.BRICK) < cost[0] ||
|
||||
gameManager.GetResourceCount(Resource.TILE) < cost[1] ||
|
||||
gameManager.GetResourceCount(Resource.GLASS) < cost[2])
|
||||
{
|
||||
Debug.Log("Not enough resources to build house!");
|
||||
return;
|
||||
}
|
||||
|
||||
gameManager.RemoveResource(Resource.BRICK, 10);
|
||||
gameManager.RemoveResource(Resource.TILE, 5);
|
||||
gameManager.RemoveResource(Resource.GLASS, 2);
|
||||
gameManager.RemoveResource(Resource.BRICK, cost[0]);
|
||||
gameManager.RemoveResource(Resource.TILE, cost[1]);
|
||||
gameManager.RemoveResource(Resource.GLASS, cost[2]);
|
||||
gameManager.AddResource(Resource.HOUSE, 1);
|
||||
}
|
||||
}
|
||||
|
||||
154
Assets/Scripts/Tutorial.cs
Normal file
154
Assets/Scripts/Tutorial.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
[System.Serializable]
|
||||
public class TutorialElement
|
||||
{
|
||||
public TutorialElement(string _title) { title = _title; }
|
||||
public string title;
|
||||
public GameObject worldObject;
|
||||
public bool complete = false;
|
||||
}
|
||||
|
||||
public enum Tutorials:int
|
||||
{
|
||||
Mining = 0,
|
||||
Production = 1,
|
||||
HouseBuilding = 2,
|
||||
MovingIn = 3,
|
||||
Assigning = 4,
|
||||
WorldMap = 5,
|
||||
Committing = 6,
|
||||
Unlocking = 7
|
||||
}
|
||||
public class Tutorial : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private TutorialElement[] tutorialElements;
|
||||
private GameManager gameManager;
|
||||
private HouseManager houseManager;
|
||||
[SerializeField]
|
||||
private float genericTimeout = 15; //Timeout for generic tutorials with no conditions
|
||||
private float genericCountdown = 0f;
|
||||
[SerializeField]
|
||||
private GameObject commitBtn;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
|
||||
houseManager = GameObject.Find("HouseManager").GetComponent<HouseManager>();
|
||||
|
||||
for (int i = 0; i < tutorialElements.Length; i++)
|
||||
{
|
||||
TutorialElement tutorial = tutorialElements[i];
|
||||
tutorial.worldObject = GameObject.Find($"{tutorial.title}Tutorial");
|
||||
if (i > 0) tutorial.worldObject.SetActive(false);
|
||||
Debug.Log($"{tutorial.title}Tutorial");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!tutorialElements[(int)Tutorials.Mining].complete)
|
||||
{
|
||||
if (gameManager.GetResourceCount(Resource.ROCK) >= 5)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.Mining].complete = true;
|
||||
tutorialElements[(int)Tutorials.Mining].worldObject.SetActive(false);
|
||||
tutorialElements[(int)Tutorials.Production].worldObject.SetActive(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.Production].complete)
|
||||
{
|
||||
if (gameManager.GetResourceCount(Resource.BRICK) > 0)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.Production].complete = true;
|
||||
tutorialElements[(int)Tutorials.Production].worldObject.SetActive(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.HouseBuilding].complete)
|
||||
{
|
||||
if (gameManager.GetResourceCount(Resource.BRICK) >= houseManager.cost[0] &&
|
||||
gameManager.GetResourceCount(Resource.TILE) >= houseManager.cost[1] &&
|
||||
gameManager.GetResourceCount(Resource.GLASS) >= houseManager.cost[2])
|
||||
{
|
||||
|
||||
tutorialElements[(int)Tutorials.HouseBuilding].worldObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (gameManager.GetResourceCount(Resource.HOUSE) > 0)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.HouseBuilding].worldObject.SetActive(false);
|
||||
tutorialElements[(int)Tutorials.HouseBuilding].complete = true;
|
||||
tutorialElements[(int)Tutorials.MovingIn].worldObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.MovingIn].complete)
|
||||
{
|
||||
if (gameManager.GetResourceCount(Resource.TOTAL_WORKER) >= 3)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.MovingIn].complete = true;
|
||||
tutorialElements[(int)Tutorials.MovingIn].worldObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.Assigning].complete)
|
||||
{
|
||||
if (gameManager.GetResourceCount(Resource.TOTAL_WORKER) >= 1)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.Assigning].worldObject.SetActive(true);
|
||||
}
|
||||
if (gameManager.GetResourceCount(Resource.WORKER) < gameManager.GetResourceCount(Resource.TOTAL_WORKER))
|
||||
{
|
||||
tutorialElements[(int)Tutorials.Assigning].complete = true;
|
||||
tutorialElements[(int)Tutorials.Assigning].worldObject.SetActive(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for 100 bricks to continue past this point
|
||||
if (!tutorialElements[(int)Tutorials.WorldMap].complete && !(gameManager.GetResourceCount(Resource.BRICK) > 50)) { return; }
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.WorldMap].complete)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.WorldMap].worldObject.SetActive(true);
|
||||
if (commitBtn.activeSelf == true)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.WorldMap].complete = true;
|
||||
tutorialElements[(int)Tutorials.WorldMap].worldObject.SetActive(false);
|
||||
tutorialElements[(int)Tutorials.Committing].worldObject.SetActive(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.Committing].complete)
|
||||
{
|
||||
if (gameManager.GetCommitedResources()[Resource.BRICK] > 0)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.Committing].complete = true;
|
||||
tutorialElements[(int)Tutorials.Committing].worldObject.SetActive(false);
|
||||
tutorialElements[(int)Tutorials.Unlocking].worldObject.SetActive(true);
|
||||
genericCountdown = genericTimeout;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tutorialElements[(int)Tutorials.Unlocking].complete)
|
||||
{
|
||||
genericCountdown -= Time.deltaTime;
|
||||
if(genericCountdown <= 0)
|
||||
{
|
||||
tutorialElements[(int)Tutorials.Unlocking].complete = true;
|
||||
tutorialElements[(int)Tutorials.Unlocking].worldObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Tutorial.cs.meta
Normal file
2
Assets/Scripts/Tutorial.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e06026c15045dcd4f927388a799502e4
|
||||
Reference in New Issue
Block a user