Animals can now move and stop and be animated to move
cow now has idle and run animation
This commit is contained in:
parent
687a37eb89
commit
2a29e5413b
2 changed files with 29 additions and 4 deletions
|
|
@ -6,14 +6,17 @@ using Random = UnityEngine.Random;
|
|||
|
||||
public class Animal : MonoBehaviour {
|
||||
private Rigidbody2D _rigidbody;
|
||||
private int _animMoveID;
|
||||
|
||||
public Item producedItem;
|
||||
public Sprite animalSprite;
|
||||
public int movementSpeed;
|
||||
public Animator animator;
|
||||
|
||||
private void Start() {
|
||||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
animalSprite = gameObject.GetComponent<SpriteRenderer>().GetComponent<Sprite>();
|
||||
_animMoveID = Animator.StringToHash("moving");
|
||||
|
||||
// Move the Animal in any random direction every 1-5s
|
||||
InvokeRepeating(nameof(MoveInRandomDirection), 2f, Random.Range(1f, 5f));
|
||||
|
|
@ -31,15 +34,15 @@ public class Animal : MonoBehaviour {
|
|||
direction.Normalize();
|
||||
|
||||
_rigidbody.velocity = movementSpeed * direction;
|
||||
StopAllCoroutines();
|
||||
animator.SetBool(_animMoveID, true);
|
||||
yield return new WaitForSeconds(randTime);
|
||||
_rigidbody.velocity = new Vector2(0f, 0f); }
|
||||
_rigidbody.velocity = new Vector2(0f, 0f);
|
||||
animator.SetBool(_animMoveID, false);
|
||||
}
|
||||
|
||||
StartCoroutine(Move());
|
||||
}
|
||||
|
||||
// TODO: Animations
|
||||
|
||||
private void OnMouseDown() {
|
||||
ActionInvoker.InvokeAction(gameObject, PlayerController.instance.SelectedItem);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue