From 263feed88008a597661587f5e8ef802f1801a1ac Mon Sep 17 00:00:00 2001 From: Sewmina Dilshan Date: Mon, 23 Jan 2023 11:03:36 +0530 Subject: [PATCH] spawning added --- Assets/Scenes/Game.unity | 272 ++++++++++++++++++++++++++++- Assets/Scripts/CameraFollower.cs | 4 + Assets/Scripts/GameManager.cs | 6 +- Assets/Scripts/OptionsSpawner.cs | 64 ++++--- Assets/Scripts/PlayerController.cs | 18 +- 5 files changed, 335 insertions(+), 29 deletions(-) diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 64c2d86..d7b253a 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -123,6 +123,72 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &175515933 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 175515936} + - component: {fileID: 175515935} + - component: {fileID: 175515934} + m_Layer: 0 + m_Name: EventSystem + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &175515934 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 175515933} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3} + m_Name: + m_EditorClassIdentifier: + m_HorizontalAxis: Horizontal + m_VerticalAxis: Vertical + m_SubmitButton: Submit + m_CancelButton: Cancel + m_InputActionsPerSecond: 10 + m_RepeatDelay: 0.5 + m_ForceModuleActive: 0 +--- !u!114 &175515935 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 175515933} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3} + m_Name: + m_EditorClassIdentifier: + m_FirstSelected: {fileID: 0} + m_sendNavigationEvents: 1 + m_DragThreshold: 10 +--- !u!4 &175515936 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 175515933} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 8 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &353788371 GameObject: m_ObjectHideFlags: 0 @@ -133,6 +199,7 @@ GameObject: m_Component: - component: {fileID: 353788373} - component: {fileID: 353788372} + - component: {fileID: 353788374} m_Layer: 0 m_Name: GameManager m_TagString: Untagged @@ -154,8 +221,9 @@ MonoBehaviour: m_EditorClassIdentifier: optionGood: {fileID: 1472984516} optionBad: {fileID: 1198253085} - SpawnDistance: 0 - SpawnTimer: 0.5 + SpawnDistanceMin: {x: 4, y: 13} + SpawnDistanceMax: {x: 15, y: 45} + SpawnTimer: 0.8 --- !u!4 &353788373 Transform: m_ObjectHideFlags: 0 @@ -170,6 +238,21 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &353788374 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 353788371} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3433d988438ba9249906784aa2e185f1, type: 3} + m_Name: + m_EditorClassIdentifier: + txt_money: {fileID: 1209384639} + moneyMultiplier: 5 + txtMoneyOffset: {x: 0, y: 2, z: 0} --- !u!1 &379229729 GameObject: m_ObjectHideFlags: 0 @@ -317,7 +400,7 @@ Camera: m_Enabled: 1 serializedVersion: 2 m_ClearFlags: 2 - m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0} + m_BackGroundColor: {r: 0.09019608, g: 0.098039225, b: 0.14509805, a: 1} m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 @@ -364,6 +447,106 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &760444830 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 760444834} + - component: {fileID: 760444833} + - component: {fileID: 760444832} + - component: {fileID: 760444831} + m_Layer: 5 + m_Name: Canvas + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &760444831 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 760444830} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!114 &760444832 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 760444830} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} + m_Name: + m_EditorClassIdentifier: + m_UiScaleMode: 0 + m_ReferencePixelsPerUnit: 100 + m_ScaleFactor: 1 + m_ReferenceResolution: {x: 800, y: 600} + m_ScreenMatchMode: 0 + m_MatchWidthOrHeight: 0 + m_PhysicalUnit: 3 + m_FallbackScreenDPI: 96 + m_DefaultSpriteDPI: 96 + m_DynamicPixelsPerUnit: 1 + m_PresetInfoIsWorld: 0 +--- !u!223 &760444833 +Canvas: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 760444830} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 0 + m_Camera: {fileID: 0} + m_PlaneDistance: 100 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_AdditionalShaderChannelsFlag: 0 + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 +--- !u!224 &760444834 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 760444830} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0, y: 0, z: 0} + m_Children: + - {fileID: 1209384638} + m_Father: {fileID: 0} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} --- !u!1 &1182127216 GameObject: m_ObjectHideFlags: 0 @@ -593,6 +776,85 @@ CircleCollider2D: m_Offset: {x: 0, y: 0} serializedVersion: 2 m_Radius: 0.5 +--- !u!1 &1209384637 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1209384638} + - component: {fileID: 1209384640} + - component: {fileID: 1209384639} + m_Layer: 5 + m_Name: Text + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1209384638 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1209384637} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 760444834} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 18.840027, y: 0} + m_SizeDelta: {x: 500, y: 50} + m_Pivot: {x: 0, y: 1} +--- !u!114 &1209384639 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1209384637} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 24 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 41 + m_Alignment: 3 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: $0 +--- !u!222 &1209384640 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1209384637} + m_CullTransparentMesh: 1 --- !u!1 &1244542280 GameObject: m_ObjectHideFlags: 0 @@ -883,8 +1145,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 63b57bf3e88333740821b0e134876b30, type: 3} m_Name: m_EditorClassIdentifier: + upwardSprite: {fileID: 21300000, guid: 35e66489d265a054a844dced54264631, type: 3} + downwardSprite: {fileID: 21300000, guid: cebae38329b50b348a19dc8302c4216b, type: 3} + normalSprite: {fileID: 21300000, guid: 9b00ede2559ce684c807348f2695f991, type: 3} eulerAngles: {x: 0, y: 0, z: 0} movingSpeed: 0.1 + boostSpeed: 0.35 turnAngle: 15 trailPrefab: {fileID: 1182127216} currentTrail: {fileID: 0} diff --git a/Assets/Scripts/CameraFollower.cs b/Assets/Scripts/CameraFollower.cs index 5d4d90b..97ce70d 100644 --- a/Assets/Scripts/CameraFollower.cs +++ b/Assets/Scripts/CameraFollower.cs @@ -23,6 +23,10 @@ public class CameraFollower : MonoBehaviour void updateFrame(){ + if(PlayerController.boosting){ + //Add boost here + } + float newX = Mathf.Lerp(transform.position.x, Target.position.x + offset.x, Xsmoothness); float newY = Mathf.Lerp(transform.position.y, Target.position.y + offset.y, Ysmoothness); transform.position = new Vector3(newX, newY, transform.position.z); diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 3314a5e..9fc371d 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -5,8 +5,12 @@ using UnityEngine.UI; public class GameManager : MonoBehaviour { public Text txt_money; + public float moneyMultiplier = 5; + public Vector3 txtMoneyOffset = Vector2.one; void Update(){ - txt_money.text = "$"+PlayerController.t.position.y.ToString(); + txt_money.text = "$"+(PlayerController.t.position.y*moneyMultiplier).ToString("n4"); + + txt_money.rectTransform.position = Camera.main.WorldToScreenPoint(PlayerController.t.position + txtMoneyOffset); } } diff --git a/Assets/Scripts/OptionsSpawner.cs b/Assets/Scripts/OptionsSpawner.cs index 983d2a0..c529cf9 100644 --- a/Assets/Scripts/OptionsSpawner.cs +++ b/Assets/Scripts/OptionsSpawner.cs @@ -4,9 +4,10 @@ using UnityEngine; public class OptionsSpawner : MonoBehaviour { - public static OptionsSpawner instance{get; private set;} - void Awake(){ - instance= this; + public static OptionsSpawner instance { get; private set; } + void Awake() + { + instance = this; } public Transform optionGood; public Transform optionBad; @@ -15,41 +16,60 @@ public class OptionsSpawner : MonoBehaviour public float SpawnTimer = 5; float t; - void Update(){ - if(!PlayerController.Started){return;} - if(t < SpawnTimer){ + void Update() + { + if (!PlayerController.Started) { return; } + if (t < SpawnTimer) + { t += Time.deltaTime; - }else{ - t=0; + } + else + { + t = 0; - float newGoodRate = Random.Range(1.05f, 1.25f); - float newBadRate = Random.Range(0.75f, 0.95f); - + float newGoodRate = 1.05f + GetRandomRateDiff(); SpawnGood(newGoodRate); - SpawnBad(newBadRate); + for (int i = 0; i < 2; i++) + { + float newBadRate = 0.95f - GetRandomRateDiff(); + SpawnBad(newBadRate); + } } } - void SpawnGood(float rate, Vector3? position = null){ - if(position ==null){ - position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x,SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y)); + + float GetRandomRateDiff() + { + float newRandom = Random.Range(1f, 100f); + + return 1- Mathf.Sqrt(newRandom) / 10f; + } + + void SpawnGood(float rate, Vector3? position = null) + { + if (position == null) + { + position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x, SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y)); } Transform newGood = Instantiate(optionGood, (Vector3)position, Quaternion.identity); newGood.GetComponentInChildren().text = $"+{((rate - 1f) * 100).ToString("n0")}%"; - newGood.name += ","+rate; + newGood.name += "," + rate; } - void SpawnBad(float rate, Vector3? position = null){ - if(position ==null){ - position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x,SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y)); + void SpawnBad(float rate, Vector3? position = null) + { + if (position == null) + { + position = PlayerController.t.position + new Vector3(PlayerController.t.right.x * Random.Range(SpawnDistanceMin.x, SpawnDistanceMax.x), PlayerController.t.right.y * Random.Range(SpawnDistanceMin.y, SpawnDistanceMax.y)); } Transform newBad = Instantiate(optionBad, (Vector3)position, Quaternion.identity); - newBad.GetComponentInChildren().text = $"-{((1f-rate) * 100).ToString("n0")}%"; - newBad.name += ","+rate; + newBad.GetComponentInChildren().text = $"-{((1f - rate) * 100).ToString("n0")}%"; + newBad.name += "," + rate; } - public void Reposition(){ + public void Reposition() + { // optionGood.position = PlayerController.instance.transform.position + (SpawnDistance * 1.5f); // optionBad.position = PlayerController.instance.transform.position + (SpawnDistance); diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 5a859ae..544fbd2 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -5,12 +5,17 @@ using UnityEngine; public class PlayerController : MonoBehaviour { public static PlayerController instance{get; private set;} + public Sprite upwardSprite; + public Sprite downwardSprite; + public Sprite normalSprite; public static Transform t {get {return instance.transform; }} void Awake(){ instance= this; + spriteRenderer = GetComponent(); } public Vector3 eulerAngles; public float movingSpeed = 1; + public float boostSpeed= 2; public float turnAngle = 15; public GameObject trailPrefab; public Transform currentTrail; @@ -18,6 +23,7 @@ public class PlayerController : MonoBehaviour public float senseRadius = 5; public bool isUp { get { return transform.eulerAngles.z != 360-turnAngle;}} + SpriteRenderer spriteRenderer; void Start() { CameraFollower.Target = transform; @@ -51,23 +57,26 @@ public class PlayerController : MonoBehaviour } } } - bool boosting =false; + public static bool boosting =false; IEnumerator giveBoost(float perc){ boosting=true; float newY = transform.position.y * perc; + spriteRenderer.sprite = (perc > 1) ? upwardSprite : downwardSprite; if(perc > 1){ while(transform.position.y < newY){ - transform.position += new Vector3(0,movingSpeed,0); + transform.position += new Vector3(0,boostSpeed,0); + if(!isUp){SwitchSide();} yield return new WaitForFixedUpdate(); } }else{ while(transform.position.y > newY){ - transform.position -= new Vector3(0,movingSpeed,0); + transform.position -= new Vector3(0,boostSpeed,0); if(isUp){SwitchSide();} yield return new WaitForFixedUpdate(); } } + spriteRenderer.sprite = normalSprite; boosting=false; } @@ -80,6 +89,9 @@ public class PlayerController : MonoBehaviour currentTrail = newTrail.transform; newTrail.GetComponent().startColor = newTrail.GetComponent().endColor = (isUp) ? Color.green:Color.red; + + // GetComponent().sprite = (isUp) ? upwardSprite : downwardSprite; + }