From 687a37eb89f5f5c39efb2ed359de0c3ddc1f921d Mon Sep 17 00:00:00 2001 From: d-hain Date: Thu, 16 Jun 2022 14:41:24 +0200 Subject: [PATCH] DayTransition working properly again Animals now move randomly (but they never stop moving) --- .../Animations/DayTransitionPanel.controller | 19 ++------ .../Animations/dayTransition_end.anim | 16 +++---- .../Animations/dayTransition_start.anim | 16 +++---- Assets/Resources/Cow.prefab | 5 +- Assets/Scenes/MainScene.unity | 4 +- Assets/Scripts/Animal.cs | 46 +++++++++---------- Assets/Scripts/DayTransitionManager.cs | 1 - ProjectSettings/ProjectVersion.txt | 4 +- 8 files changed, 51 insertions(+), 60 deletions(-) diff --git a/Assets/Resources/Animations/DayTransitionPanel.controller b/Assets/Resources/Animations/DayTransitionPanel.controller index 34c1432..719b3ec 100644 --- a/Assets/Resources/Animations/DayTransitionPanel.controller +++ b/Assets/Resources/Animations/DayTransitionPanel.controller @@ -83,13 +83,7 @@ AnimatorController: m_PrefabAsset: {fileID: 0} m_Name: DayTransitionPanel serializedVersion: 5 - m_AnimatorParameters: - - m_Name: end - m_Type: 9 - m_DefaultFloat: 0 - m_DefaultInt: 0 - m_DefaultBool: 1 - m_Controller: {fileID: 0} + m_AnimatorParameters: [] m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -165,21 +159,18 @@ AnimatorStateTransition: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: - m_Conditions: - - m_ConditionMode: 1 - m_ConditionEvent: end - m_EventTreshold: 0 + m_Conditions: [] m_DstStateMachine: {fileID: 0} m_DstState: {fileID: -2372471818689155614} m_Solo: 0 m_Mute: 0 m_IsExit: 0 serializedVersion: 3 - m_TransitionDuration: 0 + m_TransitionDuration: 0.25 m_TransitionOffset: 0 m_ExitTime: 0.75 - m_HasExitTime: 0 - m_HasFixedDuration: 0 + m_HasExitTime: 1 + m_HasFixedDuration: 1 m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 1 diff --git a/Assets/Resources/Animations/dayTransition_end.anim b/Assets/Resources/Animations/dayTransition_end.anim index 17afb8f..07608cc 100644 --- a/Assets/Resources/Animations/dayTransition_end.anim +++ b/Assets/Resources/Animations/dayTransition_end.anim @@ -22,7 +22,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -31,7 +31,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -50,7 +50,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -59,7 +59,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -122,7 +122,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -131,7 +131,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -150,7 +150,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -159,7 +159,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 diff --git a/Assets/Resources/Animations/dayTransition_start.anim b/Assets/Resources/Animations/dayTransition_start.anim index fd39746..6dddcd5 100644 --- a/Assets/Resources/Animations/dayTransition_start.anim +++ b/Assets/Resources/Animations/dayTransition_start.anim @@ -22,7 +22,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -31,7 +31,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -50,7 +50,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -59,7 +59,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -122,7 +122,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -131,7 +131,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -150,7 +150,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -159,7 +159,7 @@ AnimationClip: outWeight: 0.33333334 - serializedVersion: 3 time: 1 - value: 0 + value: 1 inSlope: 0 outSlope: 0 tangentMode: 136 diff --git a/Assets/Resources/Cow.prefab b/Assets/Resources/Cow.prefab index 23dd1d0..151d87c 100644 --- a/Assets/Resources/Cow.prefab +++ b/Assets/Resources/Cow.prefab @@ -154,5 +154,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 36cb7b1a78935094f84a770ea77f308c, type: 3} m_Name: m_EditorClassIdentifier: - animalSprite: {fileID: 0} - movementSpeed: 20 + producedItem: {fileID: 11400000, guid: 510712f2d23afc147979bcd564ef7943, type: 2} + animalSprite: {fileID: 21300000, guid: e2bde586482642d44a270276574c0129, type: 3} + movementSpeed: 1 diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index dbfaac7..f298a33 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -450,7 +450,7 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: -9.8, y: 0} + m_Offset: {x: -10.4, y: 0} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0, y: 0} @@ -1622,7 +1622,7 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: 9.8, y: 0} + m_Offset: {x: 10.4, y: 0} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0, y: 0} diff --git a/Assets/Scripts/Animal.cs b/Assets/Scripts/Animal.cs index 38ba68c..4539f1e 100644 --- a/Assets/Scripts/Animal.cs +++ b/Assets/Scripts/Animal.cs @@ -1,41 +1,41 @@ +using System; +using System.Collections; using DefaultNamespace; using UnityEngine; using Random = UnityEngine.Random; public class Animal : MonoBehaviour { - private Item _producedItem; private Rigidbody2D _rigidbody; - public Item ProducedItem => _producedItem; - + public Item producedItem; public Sprite animalSprite; public int movementSpeed; private void Start() { _rigidbody = gameObject.GetComponent(); animalSprite = gameObject.GetComponent().GetComponent(); - } - - private void Update() { - _rigidbody.rotation = 0f; - Vector2 direction = new Vector2( - Random.Range(-1f, 1f), - Random.Range(-1f, 1f)); - direction.Normalize(); - _rigidbody.velocity = movementSpeed * direction; + // Move the Animal in any random direction every 1-5s + InvokeRepeating(nameof(MoveInRandomDirection), 2f, Random.Range(1f, 5f)); } - - private void OnCollisionEnter2D(Collision2D col) { - Vector2 oldPos = _rigidbody.position; - //TODO: collide with edges working but no stopping - string[] colNames = { "Top", "Bottom", "Left", "Right" }; - foreach(string colName in colNames) { - if(colName.ToUpper().Equals(col.gameObject.name.ToUpper())) { - Debug.Log("EEEEEEEE " + col.gameObject.name); - _rigidbody.position = oldPos; - } - } + + // Moves the Animal in any random direction for a random amount of time + private void MoveInRandomDirection() { + IEnumerator Move() { + float randTime = Random.Range(0.5f, 1f); + + _rigidbody.rotation = 0f; + Vector2 direction = new Vector2( + Random.Range(-1f, 1f), + Random.Range(-1f, 1f)); + direction.Normalize(); + + _rigidbody.velocity = movementSpeed * direction; + StopAllCoroutines(); + yield return new WaitForSeconds(randTime); + _rigidbody.velocity = new Vector2(0f, 0f); } + + StartCoroutine(Move()); } // TODO: Animations diff --git a/Assets/Scripts/DayTransitionManager.cs b/Assets/Scripts/DayTransitionManager.cs index a0c15ad..afed128 100644 --- a/Assets/Scripts/DayTransitionManager.cs +++ b/Assets/Scripts/DayTransitionManager.cs @@ -21,7 +21,6 @@ public class DayTransitionManager : MonoBehaviour { private IEnumerator PlayTransition() { dayCountText.text = "Day " + HouseController.DayCount; - dayTransitionAnimator.SetTrigger("start"); yield return new WaitForSeconds(3f); sleepButton.GetComponent