From 60f39951a5948216355c42c9fbcb593f59036a37 Mon Sep 17 00:00:00 2001 From: Dom Harris Date: Sun, 10 Jan 2021 17:34:30 +0000 Subject: [PATCH] fixed stupid wraparound issue --- Assets/Prefabs/Enemy.prefab | 15 ++++++++++++ Assets/Scenes/Chief's Sandbox.unity | 4 ++-- Assets/Scripts/AddScoreOnDie.cs | 2 ++ Assets/Scripts/WrapAroundOnEnable.cs | 28 +++++++++++++++++++++++ Assets/Scripts/WrapAroundOnEnable.cs.meta | 3 +++ Assets/Weapons/Enemy.asset | 4 ++-- 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 Assets/Scripts/WrapAroundOnEnable.cs create mode 100644 Assets/Scripts/WrapAroundOnEnable.cs.meta diff --git a/Assets/Prefabs/Enemy.prefab b/Assets/Prefabs/Enemy.prefab index c81ae66..4942de9 100644 --- a/Assets/Prefabs/Enemy.prefab +++ b/Assets/Prefabs/Enemy.prefab @@ -15,6 +15,7 @@ GameObject: - component: {fileID: 2766037370157449026} - component: {fileID: 2122656558574222561} - component: {fileID: -3971665732303992234} + - component: {fileID: -4901459127090716512} m_Layer: 7 m_Name: Enemy m_TagString: Untagged @@ -136,3 +137,17 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: value: 1000 +--- !u!114 &-4901459127090716512 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1738226812227614583} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 990644fedd5c4b99befe1da660313b53, type: 3} + m_Name: + m_EditorClassIdentifier: + xMin: -10.1 + xMax: 10.1 diff --git a/Assets/Scenes/Chief's Sandbox.unity b/Assets/Scenes/Chief's Sandbox.unity index 4da9374..e0528d5 100644 --- a/Assets/Scenes/Chief's Sandbox.unity +++ b/Assets/Scenes/Chief's Sandbox.unity @@ -275,8 +275,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: spawnOnBeat: 1 - xMin: -5 - xMax: 5 + xMin: -10 + xMax: 10 --- !u!114 &531937975 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 5076175860835241000, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} diff --git a/Assets/Scripts/AddScoreOnDie.cs b/Assets/Scripts/AddScoreOnDie.cs index 63ffe84..8d41947 100644 --- a/Assets/Scripts/AddScoreOnDie.cs +++ b/Assets/Scripts/AddScoreOnDie.cs @@ -1,7 +1,9 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Weapons.Scripts; +using Random = UnityEngine.Random; public class AddScoreOnDie : MonoBehaviour { diff --git a/Assets/Scripts/WrapAroundOnEnable.cs b/Assets/Scripts/WrapAroundOnEnable.cs new file mode 100644 index 0000000..e82e552 --- /dev/null +++ b/Assets/Scripts/WrapAroundOnEnable.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +public class WrapAroundOnEnable : MonoBehaviour +{ + [SerializeField] private float xMin, xMax; + + private void OnEnable() + { + WaitUtils.Wait(Time.deltaTime, true, () => + { + + var w = Mathf.Abs(xMax - xMin); + var x = transform.localPosition.x; + if (x > xMax) + { + x -= w; + } + else if (x < xMin) + { + x += w; + } + transform.localPosition = new Vector3( + x, + transform.localPosition.y, + transform.localPosition.z); + }); + } +} \ No newline at end of file diff --git a/Assets/Scripts/WrapAroundOnEnable.cs.meta b/Assets/Scripts/WrapAroundOnEnable.cs.meta new file mode 100644 index 0000000..064428d --- /dev/null +++ b/Assets/Scripts/WrapAroundOnEnable.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 990644fedd5c4b99befe1da660313b53 +timeCreated: 1610299723 \ No newline at end of file diff --git a/Assets/Weapons/Enemy.asset b/Assets/Weapons/Enemy.asset index f33f2a4..703880d 100644 --- a/Assets/Weapons/Enemy.asset +++ b/Assets/Weapons/Enemy.asset @@ -113,12 +113,12 @@ MonoBehaviour: spawnPlane: 1 width: 0 height: 0 - surfaceOnly: 1 + surfaceOnly: 0 evenDistribution: 0 numSides: 3 numPerSide: 10 flipVertical: 0 - radius: 5 + radius: 10 arc: 360 composite: [] manualFire: 1