edge colliders on camera
animals are moving now (very bad => will get better) set BasicTile Collider2D isTrigger to false
This commit is contained in:
parent
f454e82aab
commit
3a564aa909
7 changed files with 380 additions and 86 deletions
|
|
@ -1,30 +1,46 @@
|
|||
using System;
|
||||
using DefaultNamespace;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Animal : MonoBehaviour {
|
||||
protected Sprite animalSprite;
|
||||
private Item _producedItem;
|
||||
private Rigidbody2D _rigidbody;
|
||||
|
||||
public Item ProducedItem => _producedItem;
|
||||
|
||||
|
||||
public Sprite animalSprite;
|
||||
public int movementSpeed;
|
||||
|
||||
private void Start() {
|
||||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
animalSprite = gameObject.GetComponent<SpriteRenderer>().GetComponent<Sprite>();
|
||||
|
||||
_rigidbody.velocity = new Vector2(Random.Range(1, 10),
|
||||
Random.Range(1, 10));
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
_rigidbody.velocity = new Vector2(_rigidbody.velocity.x * Random.Range(0, 10),
|
||||
_rigidbody.velocity.y * Random.Range(0, 10));// TODO: wer?
|
||||
_rigidbody.rotation = 0f;
|
||||
|
||||
Vector2 direction = new Vector2(
|
||||
Random.Range(-1f, 1f),
|
||||
Random.Range(-1f, 1f));
|
||||
direction.Normalize();
|
||||
_rigidbody.velocity = movementSpeed * direction;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Animations
|
||||
|
||||
|
||||
private void OnMouseDown() {
|
||||
ActionInvoker.InvokeAction(gameObject, PlayerController.instance.SelectedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue