From 6415a5b071943bef2fcddd5378e8318ccae36ffd Mon Sep 17 00:00:00 2001 From: MB Date: Sat, 26 Jan 2019 11:12:51 +1100 Subject: [PATCH] Camera modifications added --- Assets/Scipts/GameMode.cs | 5 +++ Assets/Scipts/Map.cs | 78 +++++++++++++++++++++++++++++++++++++++ Assets/Scipts/Map.cs.meta | 11 ++++++ Assets/Scipts/Timer.cs | 30 +++++++++------ 4 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 Assets/Scipts/Map.cs create mode 100644 Assets/Scipts/Map.cs.meta diff --git a/Assets/Scipts/GameMode.cs b/Assets/Scipts/GameMode.cs index e760750..02d57e2 100644 --- a/Assets/Scipts/GameMode.cs +++ b/Assets/Scipts/GameMode.cs @@ -68,4 +68,9 @@ public class GameMode : MonoBehaviour { } } + + public List GetPlayers() + { + return Players; + } } diff --git a/Assets/Scipts/Map.cs b/Assets/Scipts/Map.cs new file mode 100644 index 0000000..597882b --- /dev/null +++ b/Assets/Scipts/Map.cs @@ -0,0 +1,78 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Map : MonoBehaviour { + + public GameMode mode; //Reference to the scenes gamemode script + GameObject LocalPlayer; + + //Minimum and maximum values for the map + public float minX; + public float maxX; + public float minZ; + public float maxZ; + + public GameObject TopCam; + public GameObject BotCam; + public GameObject LeftCam; + public GameObject RightCam; + + //How wide halfd the camera is for the resizing + public float camWidth = 8.0f; + public float camHeight = 5.0f; + + void Update() + { + Teleport(); + HandleCameraMovement(TopCam, true); + HandleCameraMovement(BotCam, true); + HandleCameraMovement(LeftCam, false); + HandleCameraMovement(RightCam, false); + + } + + void Teleport() + { + Transform PT = localPlayer.Transform; + if (PT.position.x > maxX) + { + PT.position = new Vector3(minX, PT.position.y, PT.position.z); + } + else if (PT.position.x < minX) + { + PT.position = new Vector3(maxX, PT.position.y, PT.position.z); + } + if (PT.position.z > maxZ) + { + PT.position = new Vector3(PT.position.x, PT.position.y, minZ); + } + else if (PT.position.x < minX) + { + PT.position = new Vector3(PT.position.x, PT.position.y, maxZ); + } + + } + + /// + /// + /// + /// The camera to move + /// Do we move in the X axis or the Z? + void HandleCameraMovement(GameObject Cam, bool Xmove) + { + if (Xmove == true) + { + Cam.transform.position = new Vector3(LocalPlayer.transform.position.x, Cam.transform.position.y, Cam.transform.position.z); + } + else + { + Cam.transform.position = new Vector3(Cam.transform.position.x, Cam.transform.position.y, LocalPlayer.transform.position.z); + } + } + + void HandleCamSizing + { + + } +} diff --git a/Assets/Scipts/Map.cs.meta b/Assets/Scipts/Map.cs.meta new file mode 100644 index 0000000..a9452bf --- /dev/null +++ b/Assets/Scipts/Map.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fb1b808875f0dab4f9905cced86ca98a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Timer.cs b/Assets/Scipts/Timer.cs index 2013fcf..6990fbc 100644 --- a/Assets/Scipts/Timer.cs +++ b/Assets/Scipts/Timer.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Timer : MonoBehaviour { @@ -14,9 +15,18 @@ public class Timer : MonoBehaviour { public Color Dawn; public Color Noon; + float DawnValue; + float NoonValue; + float colorDif; + Image SunImage; + void Start() { - Sun.gameObject.GetComponent().Color = Dawn; + SunImage = Sun.gameObject.GetComponent(); + SunImage.color = Dawn; + DawnValue = Dawn.b; + NoonValue = Noon.b; + colorDif = Mathf.Abs(NoonValue - DawnValue); } void Update () { @@ -26,20 +36,18 @@ public class Timer : MonoBehaviour { //Game Lose code here } - /* - //Move the sun - float reqRot = (curTime / MaxTimer) * 180; - if (reqRot > 180) + Color newColor; + + if (curTime > MaxTimer / 2) { - reqRot = 180; + newColor = new Color(SunImage.color.r, SunImage.color.g - colorDif * ((90 / MaxTimer) * Time.deltaTime), SunImage.color.b ); + } - if (reqRot > curRot) + else { - float rotDistance = reqRot - curRot; - // Sun.RotateAround(Pivot.transform.position, Sun.transform.forward, rotDistance); - curRot = reqRot; + newColor = new Color(SunImage.color.r, SunImage.color.g + colorDif * ((90 / MaxTimer) * Time.deltaTime), SunImage.color.b); } - */ + SunImage.color = newColor; Sun.RotateAround(Pivot.transform.position, -1 * Sun.transform.forward, (180 / MaxTimer) * Time.deltaTime); }