DayTransition working properly again

Animals now move randomly (but they never stop moving)
This commit is contained in:
d-hain 2022-06-16 14:41:24 +02:00
parent 3a564aa909
commit 687a37eb89
8 changed files with 51 additions and 60 deletions

View file

@ -83,13 +83,7 @@ AnimatorController:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: DayTransitionPanel m_Name: DayTransitionPanel
serializedVersion: 5 serializedVersion: 5
m_AnimatorParameters: m_AnimatorParameters: []
- m_Name: end
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 1
m_Controller: {fileID: 0}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer
@ -165,21 +159,18 @@ AnimatorStateTransition:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: m_Name:
m_Conditions: m_Conditions: []
- m_ConditionMode: 1
m_ConditionEvent: end
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0} m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -2372471818689155614} m_DstState: {fileID: -2372471818689155614}
m_Solo: 0 m_Solo: 0
m_Mute: 0 m_Mute: 0
m_IsExit: 0 m_IsExit: 0
serializedVersion: 3 serializedVersion: 3
m_TransitionDuration: 0 m_TransitionDuration: 0.25
m_TransitionOffset: 0 m_TransitionOffset: 0
m_ExitTime: 0.75 m_ExitTime: 0.75
m_HasExitTime: 0 m_HasExitTime: 1
m_HasFixedDuration: 0 m_HasFixedDuration: 1
m_InterruptionSource: 0 m_InterruptionSource: 0
m_OrderedInterruption: 1 m_OrderedInterruption: 1
m_CanTransitionToSelf: 1 m_CanTransitionToSelf: 1

View file

@ -22,7 +22,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -31,7 +31,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -50,7 +50,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -59,7 +59,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -122,7 +122,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -131,7 +131,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -150,7 +150,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -159,7 +159,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136

View file

@ -22,7 +22,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -31,7 +31,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -50,7 +50,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -59,7 +59,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -122,7 +122,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -131,7 +131,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -150,7 +150,7 @@ AnimationClip:
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0 time: 0
value: 1 value: 0
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136
@ -159,7 +159,7 @@ AnimationClip:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0 value: 1
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 136 tangentMode: 136

View file

@ -154,5 +154,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 36cb7b1a78935094f84a770ea77f308c, type: 3} m_Script: {fileID: 11500000, guid: 36cb7b1a78935094f84a770ea77f308c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
animalSprite: {fileID: 0} producedItem: {fileID: 11400000, guid: 510712f2d23afc147979bcd564ef7943, type: 2}
movementSpeed: 20 animalSprite: {fileID: 21300000, guid: e2bde586482642d44a270276574c0129, type: 3}
movementSpeed: 1

View file

@ -450,7 +450,7 @@ BoxCollider2D:
m_IsTrigger: 0 m_IsTrigger: 0
m_UsedByEffector: 0 m_UsedByEffector: 0
m_UsedByComposite: 0 m_UsedByComposite: 0
m_Offset: {x: -9.8, y: 0} m_Offset: {x: -10.4, y: 0}
m_SpriteTilingProperty: m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0} border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0} pivot: {x: 0, y: 0}
@ -1622,7 +1622,7 @@ BoxCollider2D:
m_IsTrigger: 0 m_IsTrigger: 0
m_UsedByEffector: 0 m_UsedByEffector: 0
m_UsedByComposite: 0 m_UsedByComposite: 0
m_Offset: {x: 9.8, y: 0} m_Offset: {x: 10.4, y: 0}
m_SpriteTilingProperty: m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0} border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0} pivot: {x: 0, y: 0}

View file

@ -1,41 +1,41 @@
using System;
using System.Collections;
using DefaultNamespace; using DefaultNamespace;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
public class Animal : MonoBehaviour { public class Animal : MonoBehaviour {
private Item _producedItem;
private Rigidbody2D _rigidbody; private Rigidbody2D _rigidbody;
public Item ProducedItem => _producedItem; public Item producedItem;
public Sprite animalSprite; public Sprite animalSprite;
public int movementSpeed; public int movementSpeed;
private void Start() { private void Start() {
_rigidbody = gameObject.GetComponent<Rigidbody2D>(); _rigidbody = gameObject.GetComponent<Rigidbody2D>();
animalSprite = gameObject.GetComponent<SpriteRenderer>().GetComponent<Sprite>(); animalSprite = gameObject.GetComponent<SpriteRenderer>().GetComponent<Sprite>();
// Move the Animal in any random direction every 1-5s
InvokeRepeating(nameof(MoveInRandomDirection), 2f, Random.Range(1f, 5f));
} }
private void Update() { // Moves the Animal in any random direction for a random amount of time
_rigidbody.rotation = 0f; private void MoveInRandomDirection() {
IEnumerator Move() {
float randTime = Random.Range(0.5f, 1f);
_rigidbody.rotation = 0f;
Vector2 direction = new Vector2( Vector2 direction = new Vector2(
Random.Range(-1f, 1f), Random.Range(-1f, 1f),
Random.Range(-1f, 1f)); Random.Range(-1f, 1f));
direction.Normalize(); direction.Normalize();
_rigidbody.velocity = movementSpeed * direction;
}
private void OnCollisionEnter2D(Collision2D col) { _rigidbody.velocity = movementSpeed * direction;
Vector2 oldPos = _rigidbody.position; StopAllCoroutines();
//TODO: collide with edges working but no stopping yield return new WaitForSeconds(randTime);
string[] colNames = { "Top", "Bottom", "Left", "Right" }; _rigidbody.velocity = new Vector2(0f, 0f); }
foreach(string colName in colNames) {
if(colName.ToUpper().Equals(col.gameObject.name.ToUpper())) { StartCoroutine(Move());
Debug.Log("EEEEEEEE " + col.gameObject.name);
_rigidbody.position = oldPos;
}
}
} }
// TODO: Animations // TODO: Animations

View file

@ -21,7 +21,6 @@ public class DayTransitionManager : MonoBehaviour {
private IEnumerator PlayTransition() { private IEnumerator PlayTransition() {
dayCountText.text = "Day " + HouseController.DayCount; dayCountText.text = "Day " + HouseController.DayCount;
dayTransitionAnimator.SetTrigger("start");
yield return new WaitForSeconds(3f); yield return new WaitForSeconds(3f);
sleepButton.GetComponent<Button>().enabled = true; sleepButton.GetComponent<Button>().enabled = true;

View file

@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.1f1 m_EditorVersion: 2021.3.2f1
m_EditorVersionWithRevision: 2021.3.1f1 (3b70a0754835) m_EditorVersionWithRevision: 2021.3.2f1 (d6360bedb9a0)