mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 20:22:08 +01:00
merged mit noah und juilius
This commit is contained in:
141
Assets/Scripts/Building.cs
Normal file
141
Assets/Scripts/Building.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Building : MonoBehaviour
|
||||
{
|
||||
[Header("Main-Info")]
|
||||
[SerializeField] string Title = "Building";
|
||||
[SerializeField] string Description = "This is a building!";
|
||||
[SerializeField] int Level = 1;
|
||||
[SerializeField] int Health = 100;
|
||||
|
||||
|
||||
[Header("Build-Ressources")]
|
||||
[SerializeField] int Wood = 0;
|
||||
[SerializeField] int Stone = 0;
|
||||
[SerializeField] int Clay = 0;
|
||||
[SerializeField] int Straw = 0;
|
||||
|
||||
[Header("Building")]
|
||||
private Material oldMaterial;
|
||||
private Color originalColor;
|
||||
private bool isPlacingBuilding = false;
|
||||
public int isColliding;
|
||||
private new Renderer renderer;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
BuildingStart();
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
BuildingUpdate();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void BuildingStart()
|
||||
{
|
||||
renderer = GetComponent<Renderer>();
|
||||
originalColor = renderer.material.color;
|
||||
}
|
||||
public void BuildingUpdate()
|
||||
{
|
||||
if (!isPlacingBuilding)
|
||||
{
|
||||
renderer.material = oldMaterial;
|
||||
isColliding = 0;
|
||||
}
|
||||
if (isColliding > 0)
|
||||
{
|
||||
changeMaterialToTransparent(renderer.material);
|
||||
renderer.material.color = new Color(1, 0, 0, 0.3f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isPlacingBuilding)
|
||||
{
|
||||
changeMaterialToTransparent(renderer.material);
|
||||
renderer.material.color = new Color(0, 0, 1, 0.3f);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetComponent<Renderer>().material.color = originalColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setTitle(string newTitle) { // Sets Title for building
|
||||
Title = newTitle;
|
||||
}
|
||||
public string getTitle() { // Returns Title of building
|
||||
return Title;
|
||||
}
|
||||
public void setDescription(string newDescription) { // Sets Description for building
|
||||
Description = newDescription;
|
||||
}
|
||||
public string getDescription() { // Returns Description of building
|
||||
return Description;
|
||||
}
|
||||
public void setHealth(int newHealth) { // Sets Health for building
|
||||
Health = newHealth;
|
||||
}
|
||||
public int getHealth() { // Returns Health of building
|
||||
return Health;
|
||||
}
|
||||
public void setLevel(int newLevel) {
|
||||
Level = newLevel;
|
||||
}
|
||||
public int getLevel() {
|
||||
return Level;
|
||||
}
|
||||
public bool delete() {
|
||||
// if delete successfully return true else return false
|
||||
return true;
|
||||
}
|
||||
|
||||
public void isPlacing(bool isCurrentlyPlacing)
|
||||
{
|
||||
if (isCurrentlyPlacing)
|
||||
{
|
||||
isPlacingBuilding = true;
|
||||
return;
|
||||
}
|
||||
changeMaterialToOpaque(renderer.material);
|
||||
renderer.material.color = new Color(1, 1, 1, 1);
|
||||
isPlacingBuilding = false;
|
||||
}
|
||||
void OnCollisionEnter(Collision col)
|
||||
{
|
||||
isColliding += 1;
|
||||
}
|
||||
void OnCollisionExit(Collision col)
|
||||
{
|
||||
isColliding -= 1;
|
||||
}
|
||||
|
||||
void changeMaterialToOpaque(Material material)
|
||||
{
|
||||
material.SetOverrideTag("RenderType", "");
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.SetInt("_ZWrite", 1);
|
||||
material.DisableKeyword("_ALPHATEST_ON");
|
||||
material.DisableKeyword("_ALPHABLEND_ON");
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.renderQueue = -1;
|
||||
}
|
||||
void changeMaterialToTransparent(Material material)
|
||||
{
|
||||
material.SetOverrideTag("RenderType", "Transparent");
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.SetInt("_ZWrite", 0);
|
||||
material.DisableKeyword("_ALPHATEST_ON");
|
||||
material.EnableKeyword("_ALPHABLEND_ON");
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Building.cs.meta
Normal file
11
Assets/Scripts/Building.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 663feed4d05ec994fb1deb18b1767962
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
Assets/Scripts/BuildingPlacement.cs
Normal file
66
Assets/Scripts/BuildingPlacement.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BuildingPlacement : MonoBehaviour
|
||||
{
|
||||
TerrainCollider terrainCollider;
|
||||
public GameObject terrain;
|
||||
Ray ray;
|
||||
public float rotation = 0;
|
||||
[SerializeField] public GameObject building;
|
||||
[SerializeField] bool isPlacing = false;
|
||||
private Building currentBuilding;
|
||||
|
||||
void Start()
|
||||
{
|
||||
currentBuilding = building.GetComponent<Building>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown("Build")) { // Wenn man den Button 'B'
|
||||
if (isPlacing) { // Wenn man 'B' zum zweiten mal dr<64>ckt
|
||||
isPlacing = false;
|
||||
currentBuilding.isColliding = 0;
|
||||
currentBuilding.isPlacing(false);
|
||||
building.SetActive(false); // Blueprint wird deaktiviert
|
||||
}
|
||||
else { // Wenn man zum ersten mal 'B' dr<64>ckt
|
||||
building.SetActive(true); // Blueprint wird aktiviert
|
||||
isPlacing = true;
|
||||
}
|
||||
}
|
||||
if (building.transform != null && isPlacing) {
|
||||
currentBuilding.isPlacing(true);
|
||||
getRaycastMousePosition();
|
||||
rotateObject();
|
||||
if (Input.GetMouseButtonDown(0) && currentBuilding.isColliding == 0) { // Wenn es nicht Collidiert und man Links Klickt
|
||||
isPlacing = false;
|
||||
currentBuilding.isPlacing(false);
|
||||
Instantiate(building, building.transform.position, building.transform.rotation); // Placed das Gebäude
|
||||
building.SetActive(false); // Blueprint wird deaktiviert
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void getRaycastMousePosition() // Position of Mouse in World-Space
|
||||
{
|
||||
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hitData;
|
||||
if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity))
|
||||
{
|
||||
building.transform.position = hitData.point;
|
||||
}
|
||||
}
|
||||
void rotateObject()
|
||||
{
|
||||
if (Input.GetButtonDown("CounterRotate")) { // If Player presses button 'Left ALT' + 'R'
|
||||
building.transform.Rotate(0, -10, 0); // Rotates the building counter clockwise
|
||||
}
|
||||
else if (Input.GetButtonDown("Rotate")) { // If Player presses button 'R'
|
||||
building.transform.Rotate(0, 10, 0); // Rotates the building clockwise
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/BuildingPlacement.cs.meta
Normal file
11
Assets/Scripts/BuildingPlacement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcb2e348649dbce439cf77846fd11cd6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,11 +7,11 @@ public class EventLog : MonoBehaviour
|
||||
[Header("Event Log")]
|
||||
[SerializeField] private GameObject eventObject;
|
||||
[SerializeField] private Transform parentEventObject;
|
||||
Vector3 position = new Vector3 (796f, 134f, 0f);
|
||||
Vector3 position = new Vector3 (Screen.width - 150, 134f, 0f);
|
||||
[SerializeField] GameObject[] events;
|
||||
void Start()
|
||||
{
|
||||
|
||||
events = GameObject.FindGameObjectsWithTag("Event");
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class EventLog : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
events = GameObject.FindGameObjectsWithTag("Event");
|
||||
|
||||
//Debug.Log(events.Length);
|
||||
if(events.Length < 4)
|
||||
{
|
||||
switch (events.Length)
|
||||
@@ -45,22 +45,22 @@ public class EventLog : MonoBehaviour
|
||||
switch (events.Length)
|
||||
{
|
||||
case 1:
|
||||
events[0].transform.position = new Vector3(796f, 134f, 0f);
|
||||
events[0].transform.position = new Vector3(Screen.width - 150, 134f, 0f);
|
||||
break;
|
||||
case 2:
|
||||
events[0].transform.position = new Vector3(796f, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(796f, 174f, 0f);
|
||||
events[0].transform.position = new Vector3(Screen.width - 150, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(Screen.width - 150, 174f, 0f);
|
||||
break;
|
||||
case 3:
|
||||
events[0].transform.position = new Vector3(796f, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(796f, 174f, 0f);
|
||||
events[2].transform.position = new Vector3(796f, 214f, 0f);
|
||||
events[0].transform.position = new Vector3(Screen.width - 150, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(Screen.width - 150, 174f, 0f);
|
||||
events[2].transform.position = new Vector3(Screen.width - 150, 214f, 0f);
|
||||
break;
|
||||
case 4:
|
||||
events[0].transform.position = new Vector3(796f, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(796f, 174f, 0f);
|
||||
events[2].transform.position = new Vector3(796f, 214f, 0f);
|
||||
events[3].transform.position = new Vector3(796f, 254f, 0f);
|
||||
events[0].transform.position = new Vector3(Screen.width - 150, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(Screen.width - 150, 174f, 0f);
|
||||
events[2].transform.position = new Vector3(Screen.width - 150, 214f, 0f);
|
||||
events[3].transform.position = new Vector3(Screen.width - 150, 254f, 0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -72,8 +72,12 @@ public class EventLog : MonoBehaviour
|
||||
|
||||
public void CreateEvent(string msg)
|
||||
{
|
||||
Instantiate(eventObject, position, Quaternion.identity, parentEventObject);
|
||||
eventObject.GetComponent<EventScript>().ChangeText(msg);
|
||||
if(events.Length < 4)
|
||||
{
|
||||
Instantiate(eventObject, position, Quaternion.identity, parentEventObject);
|
||||
eventObject.GetComponent<EventScript>().ChangeText(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class LightSwitch : Interactable
|
||||
{
|
||||
public GameObject GameManager;
|
||||
public Light m_Light;
|
||||
public bool isOn;
|
||||
|
||||
@@ -29,7 +30,16 @@ public class LightSwitch : Interactable
|
||||
public override void Interact()
|
||||
{
|
||||
isOn = !isOn;
|
||||
Debug.Log("Click Light");
|
||||
|
||||
if (isOn) {
|
||||
GameManager.GetComponent<EventLog>().CreateEvent("Licht2");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameManager.GetComponent<EventLog>().CreateEvent("Licht1");
|
||||
}
|
||||
|
||||
//Debug.Log("Click Light");
|
||||
UpdateLight();
|
||||
}
|
||||
}
|
||||
|
||||
30
Assets/Scripts/PathGenerator.cs
Normal file
30
Assets/Scripts/PathGenerator.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PathNode
|
||||
{
|
||||
|
||||
private Vector3 position;
|
||||
public Vector2 index;
|
||||
private float scoreF;
|
||||
private float scoreG;
|
||||
private float scoreH;
|
||||
public List<PathNode> neigbors;
|
||||
|
||||
private PathNode previous;
|
||||
|
||||
public PathNode(Vector3 Pos) {
|
||||
neigbors = new List<PathNode>();
|
||||
position = Pos;
|
||||
scoreG = Mathf.Infinity;
|
||||
scoreF = Mathf.Infinity;
|
||||
scoreH = Mathf.Infinity;
|
||||
}
|
||||
|
||||
public Vector3 Position { get => position; set => position = value; }
|
||||
public float Hscore { get => scoreH; set => scoreH = value; }
|
||||
public float Gscore { get => scoreG; set => scoreG = value; }
|
||||
public float Fscore { get => scoreF; set => scoreF = value; }
|
||||
public PathNode Previous { get => previous; set => previous = value; }
|
||||
}
|
||||
11
Assets/Scripts/PathGenerator.cs.meta
Normal file
11
Assets/Scripts/PathGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f50f0a081672ea4a9bc9f13de003f0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
230
Assets/Scripts/PathMap.cs
Normal file
230
Assets/Scripts/PathMap.cs
Normal file
@@ -0,0 +1,230 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PathMap : MonoBehaviour
|
||||
{
|
||||
private Vector3 position;
|
||||
private PathNode[,] map;
|
||||
private GameObject[,] ball;
|
||||
private int rows = 200;
|
||||
private int cols = 200;
|
||||
private float spacing = 1f;
|
||||
private float height = 0;
|
||||
|
||||
private PathNode[] uncheckedNodes;
|
||||
private List<PathNode> openList;
|
||||
private List<PathNode> closedList;
|
||||
private List<PathNode> nextList;
|
||||
|
||||
private List<PathNode> path;
|
||||
|
||||
void Start()
|
||||
{
|
||||
path = new List<PathNode>();
|
||||
map = new PathNode[1000, 1000];
|
||||
ball = new GameObject[rows, cols];
|
||||
openList = new List<PathNode>();
|
||||
closedList = new List<PathNode>();
|
||||
nextList = new List<PathNode>();
|
||||
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
PathNode node = new PathNode(new Vector3(r * spacing, height, c * spacing));
|
||||
node.index = new Vector2(r, c);
|
||||
map[r, c] = node;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
AddAllNeighbors(new Vector2(r, c));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
sphere.transform.position = map[r, c].Position;
|
||||
ball[r, c] = sphere;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QueryNodes(new Vector3(0.7f, 2, 0.7f), new Vector3(2.5f, 0, 2.5f));
|
||||
}
|
||||
private void AddAllNeighbors(Vector2 index)
|
||||
{
|
||||
if ((int)index.x - 1 >= 0 && (int)index.y - 1 >= 0)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x - 1, (int)index.y - 1]);
|
||||
}
|
||||
if ((int)index.y - 1 >= 0)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x, (int)index.y - 1]);
|
||||
}
|
||||
if ((int)index.x + 1 < rows && (int)index.y - 1 >= 0)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x + 1, (int)index.y - 1]);
|
||||
}
|
||||
|
||||
if ((int)index.x - 1 >= 0)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x - 1, (int)index.y]);
|
||||
}
|
||||
if ((int)index.x + 1 < rows && (int)index.y >= 0)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x + 1, (int)index.y]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((int)index.x - 1 >= 0 && (int)index.y + 1 < cols)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x - 1, (int)index.y + 1]);
|
||||
}
|
||||
if ((int)index.y + 1 < cols)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x, (int)index.y + 1]);
|
||||
}
|
||||
if ((int)index.x + 1 < rows && (int)index.y + 1 < cols)
|
||||
{
|
||||
map[(int)index.x, (int)index.y].neigbors.Add(map[(int)index.x + 1, (int)index.y + 1]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private PathNode FindClosestNode(Vector3 pos)
|
||||
{
|
||||
if (pos.x > 0 && pos.x < rows * spacing && pos.z > 0 && pos.z < cols * spacing)
|
||||
{
|
||||
//Destroy(ball[Mathf.RoundToInt(pos.x / spacing), Mathf.RoundToInt(pos.z / spacing)]);
|
||||
return map[Mathf.RoundToInt(pos.x / 2), Mathf.RoundToInt(pos.z / 2)];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void QueryNodes(Vector3 Vstart, Vector3 Vend)
|
||||
{
|
||||
|
||||
bool finished = false;
|
||||
|
||||
PathNode start = FindClosestNode(Vstart);
|
||||
start.Gscore = 0;
|
||||
PathNode end = map[199, 150];
|
||||
Debug.Log(end.index);
|
||||
|
||||
openList.Add(start);
|
||||
|
||||
PathNode current;
|
||||
Debug.Log(Time.time);
|
||||
int d = 0;
|
||||
while (!finished)
|
||||
{
|
||||
d++;
|
||||
if (d > 10000)
|
||||
{
|
||||
Debug.Log("Mist");
|
||||
return;
|
||||
}
|
||||
int winner = 0;
|
||||
for (int i = 0; i < openList.Count; i++)
|
||||
{
|
||||
|
||||
if (openList[i].Fscore < openList[winner].Fscore) winner = i;
|
||||
}
|
||||
current = openList[winner];
|
||||
openList.RemoveAt(winner);
|
||||
closedList.Add(current);
|
||||
Destroy(ball[(int)current.index.x, (int)current.index.y]);
|
||||
|
||||
|
||||
|
||||
if (current != end)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
foreach (PathNode p in current.neigbors)
|
||||
{
|
||||
if (!closedList.Contains(p))
|
||||
{
|
||||
|
||||
float tempG = current.Gscore + heuristic(p.Position, current.Position);
|
||||
bool newPath = false;
|
||||
if (openList.Contains(p))
|
||||
{
|
||||
|
||||
|
||||
if (tempG < p.Gscore)
|
||||
{
|
||||
p.Gscore = tempG;
|
||||
newPath = true;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Gscore = tempG;
|
||||
newPath = true;
|
||||
openList.Add(p);
|
||||
|
||||
}
|
||||
if (newPath)
|
||||
{
|
||||
p.Hscore = heuristic(p.Position, end.Position);
|
||||
p.Fscore = p.Gscore + p.Hscore;
|
||||
p.Previous = current;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PathNode temp = end;
|
||||
path.Add(temp);
|
||||
while (temp.Previous != null)
|
||||
{
|
||||
path.Add(temp.Previous);
|
||||
temp = temp.Previous;
|
||||
}
|
||||
Debug.Log(path.Count);
|
||||
Debug.Log("yeet it finished");
|
||||
Debug.Log(Time.time);
|
||||
for (int i = path.Count - 1; i >= 0;i-- )
|
||||
{
|
||||
//Debug.Log(path[i].index);
|
||||
}
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private float heuristic(Vector3 pos1, Vector3 pos2)
|
||||
{
|
||||
return Vector3.Distance(pos1, pos2);
|
||||
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/Scripts/PathMap.cs.meta
Normal file
11
Assets/Scripts/PathMap.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49bd52c676aea7140a49d1803a03926a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,7 +10,7 @@ public class TimeManager : MonoBehaviour
|
||||
[Header("TimeManager")]
|
||||
[SerializeField] private float timePeriod = 0.02f;
|
||||
|
||||
public int secondsOfDay = 0;
|
||||
public int secondsOfDay = 2000;
|
||||
|
||||
|
||||
private void Start()
|
||||
|
||||
42
Assets/Scripts/TimeSwitchBtn.cs
Normal file
42
Assets/Scripts/TimeSwitchBtn.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeSwitchBtn: Interactable
|
||||
{
|
||||
public GameObject GameManager;
|
||||
public bool dark;
|
||||
|
||||
|
||||
public override string GetDescription()
|
||||
{
|
||||
if (dark)
|
||||
{
|
||||
|
||||
return "Press [E] to skip to <color=red>night</color>.";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return "Press [E] to skip to <color=green>day</color>.";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Interact()
|
||||
{
|
||||
|
||||
|
||||
if (dark)
|
||||
{
|
||||
GameManager.GetComponent<EventLog>().CreateEvent("Tag!");
|
||||
GameManager.GetComponent<TimeManager>().secondsOfDay = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameManager.GetComponent<EventLog>().CreateEvent("Nacht!");
|
||||
GameManager.GetComponent<TimeManager>().secondsOfDay = 30000;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TimeSwitchBtn.cs.meta
Normal file
11
Assets/Scripts/TimeSwitchBtn.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad4b82b55525b1340a96ff6b5cdd63dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user