From da2d66ed82bec696e2d759fc1e9215fabea07ce3 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 29 Sep 2017 17:07:07 +0200 Subject: Minor design tweaks --- td/Assets/Scripts/Enemy.cs | 11 ++--------- td/Assets/Scripts/EnemySpawner.cs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'td/Assets/Scripts') diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs index 7273370..edd9e29 100644 --- a/td/Assets/Scripts/Enemy.cs +++ b/td/Assets/Scripts/Enemy.cs @@ -6,18 +6,11 @@ public class Enemy : MonoBehaviour { public float speed; public float initialHp; - public Transform pathWay; + public List waypoints; - List waypoints = new List(); Vector3 waypointPos; int waypointNum = -1; // Using minus one so that first addition returns 0, first element in array - void Start () { - foreach (Transform child in pathWay) { - waypoints.Add (child.position); - } - } - void Update () { updateWaypoint (); @@ -32,7 +25,7 @@ public class Enemy : MonoBehaviour { void updateWaypoint() { if ( (transform.position == waypointPos && waypointNum < waypoints.Count - 1) || waypointNum == -1) { waypointNum++; - waypointPos = new Vector3 (waypoints [waypointNum].x, 0.604f, waypoints [waypointNum].z); + waypointPos = new Vector3 (waypoints [waypointNum].x, 0.483f, waypoints [waypointNum].z); } } diff --git a/td/Assets/Scripts/EnemySpawner.cs b/td/Assets/Scripts/EnemySpawner.cs index eb0dd43..f1eeb84 100644 --- a/td/Assets/Scripts/EnemySpawner.cs +++ b/td/Assets/Scripts/EnemySpawner.cs @@ -7,11 +7,18 @@ public class EnemySpawner : MonoBehaviour { public Enemy enemyPrefab; public Transform pathWay; public Transform gameWorld; + List waypoints = new List(); int wave; int next = 1; int n = 0; + void Awake() { + foreach (Transform child in pathWay) { + waypoints.Add (child.position); + } + } + void Update () { n++; @@ -20,8 +27,13 @@ public class EnemySpawner : MonoBehaviour { next = (int)Random.Range (50, 400); Enemy newEnemy = Instantiate (enemyPrefab, new Vector3(0, 0, 0), Quaternion.identity, gameWorld); - newEnemy.GetComponent ().pathWay = pathWay; - newEnemy.GetComponent ().speed = Random.Range (0.3f, 1.2f); + Enemy script = newEnemy.GetComponent (); + Transform transform = newEnemy.GetComponent (); + + script.waypoints = waypoints; + script.speed = Random.Range (0.3f, 1.2f); + transform.position = new Vector3 (0.93f, 0.483f, 0f); } + } } -- cgit v1.2.3 From 9fbde9c25ee0707379ef7bd7a1b8d4a2e9531437 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Fri, 29 Sep 2017 17:27:14 +0200 Subject: Small workaround for where the enemy catches player --- td/Assets/Scenes/Level 1.unity | Bin 47656 -> 47976 bytes td/Assets/Scripts/Enemy.cs | 15 ++++++--------- td/Assets/Scripts/EnemySpawner.cs | 3 +-- td/Assets/Scripts/cameraHandler.cs | 4 ++-- 4 files changed, 9 insertions(+), 13 deletions(-) (limited to 'td/Assets/Scripts') diff --git a/td/Assets/Scenes/Level 1.unity b/td/Assets/Scenes/Level 1.unity index d48cc6e..aeb84e1 100644 Binary files a/td/Assets/Scenes/Level 1.unity and b/td/Assets/Scenes/Level 1.unity differ diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs index edd9e29..bd64bd5 100644 --- a/td/Assets/Scripts/Enemy.cs +++ b/td/Assets/Scripts/Enemy.cs @@ -12,21 +12,18 @@ public class Enemy : MonoBehaviour { int waypointNum = -1; // Using minus one so that first addition returns 0, first element in array void Update () { - updateWaypoint (); + if ( (transform.position == waypointPos && waypointNum + 1 < waypoints.Count) || waypointNum == -1) { + waypointNum++; + waypointPos = new Vector3 (waypoints [waypointNum].x, 0.483f, waypoints [waypointNum].z); + } float transformStep = speed * Time.deltaTime; transform.position = Vector3.MoveTowards (transform.position, waypointPos, transformStep); - if (waypointNum == waypoints.Count - 1) { + // Selfdestruct if object reached the end + if (waypointNum + 1 >= waypoints.Count) { Destroy (gameObject); } } - - void updateWaypoint() { - if ( (transform.position == waypointPos && waypointNum < waypoints.Count - 1) || waypointNum == -1) { - waypointNum++; - waypointPos = new Vector3 (waypoints [waypointNum].x, 0.483f, waypoints [waypointNum].z); - } - } } diff --git a/td/Assets/Scripts/EnemySpawner.cs b/td/Assets/Scripts/EnemySpawner.cs index f1eeb84..df82b34 100644 --- a/td/Assets/Scripts/EnemySpawner.cs +++ b/td/Assets/Scripts/EnemySpawner.cs @@ -7,9 +7,8 @@ public class EnemySpawner : MonoBehaviour { public Enemy enemyPrefab; public Transform pathWay; public Transform gameWorld; - List waypoints = new List(); - int wave; + List waypoints = new List(); int next = 1; int n = 0; diff --git a/td/Assets/Scripts/cameraHandler.cs b/td/Assets/Scripts/cameraHandler.cs index a4aa660..0504a23 100644 --- a/td/Assets/Scripts/cameraHandler.cs +++ b/td/Assets/Scripts/cameraHandler.cs @@ -36,9 +36,9 @@ public class cameraHandler : MonoBehaviour { if (Input.touchSupported && Application.platform != RuntimePlatform.WebGLPlayer) { HandleTouch(); } else { - //HandleMouse(); + HandleMouse(); } - HandleTouch (); + //HandleTouch (); } void HandleTouch() { -- cgit v1.2.3 From bbf0d25b4681366780a9ed3755c6a1f1619d9996 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sat, 30 Sep 2017 14:11:11 +0200 Subject: Made pausemenu and sidebar --- td/Assets/Scenes/Level 1.unity | Bin 76448 -> 80776 bytes td/Assets/Scripts/mainGUI.cs | 74 +++++++++++++++++++++++++++++++ td/Assets/Scripts/mainGUI.cs.meta | 12 +++++ td/ProjectSettings/QualitySettings.asset | Bin 4976 -> 4976 bytes 4 files changed, 86 insertions(+) create mode 100644 td/Assets/Scripts/mainGUI.cs create mode 100644 td/Assets/Scripts/mainGUI.cs.meta (limited to 'td/Assets/Scripts') diff --git a/td/Assets/Scenes/Level 1.unity b/td/Assets/Scenes/Level 1.unity index 42b0d2e..5cc1e86 100644 Binary files a/td/Assets/Scenes/Level 1.unity and b/td/Assets/Scenes/Level 1.unity differ diff --git a/td/Assets/Scripts/mainGUI.cs b/td/Assets/Scripts/mainGUI.cs new file mode 100644 index 0000000..3c135b2 --- /dev/null +++ b/td/Assets/Scripts/mainGUI.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine.UI; +using UnityEngine; + +public class mainGUI : MonoBehaviour { + + GameObject pnlMenu; + GameObject pnlSidebar; + RectTransform pnlSidebarTransform; + Button btnToggleSidebar; + Button btnPauseGame; + Button btnResumeGame; + + bool sidebarExpanded; + float[] sidebarStates = new float[2] {0f, -202.4f}; // The x position of the sidebar expanded or collapsed + + bool menuActive; + + void Awake() { + /* Panels */ + pnlMenu = transform.Find ("menu").gameObject; + pnlSidebar = transform.Find ("sidebarWrapper").gameObject; + pnlSidebarTransform = pnlSidebar.GetComponent (); + + /* Buttons */ + btnToggleSidebar = pnlSidebar.transform.Find("toggleSidebar").gameObject.GetComponent