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_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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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}

View file

@ -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<Rigidbody2D>();
animalSprite = gameObject.GetComponent<SpriteRenderer>().GetComponent<Sprite>();
}
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

View file

@ -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<Button>().enabled = true;