mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 20:22:08 +01:00
basic time system, test terrain, event log
This commit is contained in:
79
Assets/Scripts/EventLog.cs
Normal file
79
Assets/Scripts/EventLog.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EventLog : MonoBehaviour
|
||||
{
|
||||
[Header("Event Log")]
|
||||
[SerializeField] private GameObject eventObject;
|
||||
[SerializeField] private Transform parentEventObject;
|
||||
Vector3 position = new Vector3 (796f, 134f, 0f);
|
||||
[SerializeField] GameObject[] events;
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
events = GameObject.FindGameObjectsWithTag("Event");
|
||||
|
||||
if(events.Length < 4)
|
||||
{
|
||||
switch (events.Length)
|
||||
{
|
||||
case 0:
|
||||
position.y = 134f;
|
||||
break;
|
||||
case 1:
|
||||
position.y = 174f;
|
||||
break;
|
||||
case 2:
|
||||
position.y = 214f;
|
||||
break;
|
||||
case 3:
|
||||
position.y = 254f;
|
||||
break;
|
||||
}
|
||||
|
||||
//Relocate
|
||||
|
||||
for (int i = 0; i < events.Length; i++)
|
||||
{
|
||||
switch (events.Length)
|
||||
{
|
||||
case 1:
|
||||
events[0].transform.position = new Vector3(796f, 134f, 0f);
|
||||
break;
|
||||
case 2:
|
||||
events[0].transform.position = new Vector3(796f, 134f, 0f);
|
||||
events[1].transform.position = new Vector3(796f, 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);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void CreateEvent(string msg)
|
||||
{
|
||||
Instantiate(eventObject, position, Quaternion.identity, parentEventObject);
|
||||
eventObject.GetComponent<EventScript>().ChangeText(msg);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/EventLog.cs.meta
Normal file
11
Assets/Scripts/EventLog.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41974f676d374a946813f4863f75f978
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Scripts/EventScript.cs
Normal file
31
Assets/Scripts/EventScript.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EventScript : MonoBehaviour
|
||||
{
|
||||
//[SerializeField] private Text text;
|
||||
void Start()
|
||||
{
|
||||
|
||||
Invoke("Delete", 5f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ChangeText(string msg)
|
||||
{
|
||||
Text t = GetComponentInChildren<Text>();
|
||||
t.text = msg;
|
||||
}
|
||||
|
||||
void Delete()
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EventScript.cs.meta
Normal file
11
Assets/Scripts/EventScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9be9743e89535f6429f5773fd772d746
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,10 +9,12 @@ public class PlayerMovement : MonoBehaviour
|
||||
//[SerializeField] private Transform playerTransform;
|
||||
[SerializeField] private float speed = 12f;
|
||||
[SerializeField] private float airSpeed = 0.6f;
|
||||
[SerializeField] private float sneakSpeed = 0.4f;
|
||||
[SerializeField] private float sprintSpeed = 1.8f;
|
||||
[SerializeField] private float sprintAirSpeed = 1.4f;
|
||||
[SerializeField] private float gravity = -9.81f;
|
||||
[SerializeField] private float jumpHeight = 3f;
|
||||
|
||||
|
||||
[SerializeField] private Transform groundCheck;
|
||||
[SerializeField] private float groundDistance = 0.4f;
|
||||
@@ -21,12 +23,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
private Vector3 velocity;
|
||||
private bool isGrounded;
|
||||
private bool isSprinting = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private bool isSneaking = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
@@ -64,9 +61,14 @@ public class PlayerMovement : MonoBehaviour
|
||||
//SNEAK
|
||||
if (Input.GetButton("Sneak"))
|
||||
{
|
||||
print("Sneak");
|
||||
move *= sneakSpeed;
|
||||
isSneaking = true;
|
||||
//Kommt mit character model und animations
|
||||
}
|
||||
else
|
||||
{
|
||||
isSneaking = false;
|
||||
}
|
||||
isSprinting = false;
|
||||
}
|
||||
|
||||
|
||||
129
Assets/Scripts/TimeManager.cs
Normal file
129
Assets/Scripts/TimeManager.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
//Eine Minute geht 0.23 Sekunden
|
||||
|
||||
public class TimeManager : MonoBehaviour
|
||||
{
|
||||
[Header("TimeManager")]
|
||||
[SerializeField] private float timePeriod = 3f;
|
||||
[SerializeField] private Text timeUI;
|
||||
|
||||
public int minutes = 0;
|
||||
public int hours = 0;
|
||||
public string current_time = "";
|
||||
|
||||
public int day = 1;
|
||||
public int month = 1;
|
||||
public int year = -5000;
|
||||
public string yearStr = "";
|
||||
public string current_date = "";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InvokeRepeating("timeUpdate", 1f, timePeriod);
|
||||
}
|
||||
|
||||
|
||||
void timeUpdate()
|
||||
{
|
||||
//Count
|
||||
minutes += 1;
|
||||
|
||||
countTime();
|
||||
countDate();
|
||||
|
||||
timeUI.text = current_time;
|
||||
|
||||
/*
|
||||
Debug.Log(current_time);
|
||||
Debug.Log(current_date);
|
||||
*/
|
||||
}
|
||||
|
||||
private void countTime()
|
||||
{
|
||||
//Time
|
||||
if (minutes >= 60)
|
||||
{
|
||||
minutes = 0;
|
||||
hours += 1;
|
||||
}
|
||||
|
||||
|
||||
//Current Time String
|
||||
if (hours <= 9)
|
||||
{
|
||||
current_time = "0" + hours + ":";
|
||||
}
|
||||
else
|
||||
{
|
||||
current_time = hours + ":";
|
||||
}
|
||||
|
||||
if (minutes <= 9)
|
||||
{
|
||||
current_time += "0" + minutes;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_time += minutes;
|
||||
}
|
||||
}
|
||||
|
||||
private void countDate()
|
||||
{
|
||||
//Date
|
||||
if (hours >= 24)
|
||||
{
|
||||
hours = 0;
|
||||
day += 1;
|
||||
}
|
||||
else if (day > 31)
|
||||
{
|
||||
day = 1;
|
||||
month += 1;
|
||||
}
|
||||
else if (month > 12)
|
||||
{
|
||||
month = 1;
|
||||
year += 1;
|
||||
}
|
||||
|
||||
//Format Year
|
||||
if (year < 0)
|
||||
{
|
||||
yearStr = year * -1 + "B.C.";
|
||||
}
|
||||
else if (year > 0)
|
||||
{
|
||||
yearStr = year + "A.C.";
|
||||
}
|
||||
else
|
||||
{
|
||||
yearStr = "0";
|
||||
}
|
||||
|
||||
//current Date
|
||||
if (day <= 9)
|
||||
{
|
||||
current_date = "0" + day + "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
current_date = day + "/";
|
||||
}
|
||||
|
||||
if (month <= 9)
|
||||
{
|
||||
current_date += "0" + month + "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
current_date += month + "/";
|
||||
}
|
||||
|
||||
current_date += yearStr;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TimeManager.cs.meta
Normal file
11
Assets/Scripts/TimeManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94aea2e8606a6154da5328aefe2b6705
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user