edge colliders on camera

animals are moving now (very bad => will get better)
set BasicTile Collider2D isTrigger to false
This commit is contained in:
d-hain 2022-06-10 17:51:46 +02:00
parent f454e82aab
commit 3a564aa909
7 changed files with 380 additions and 86 deletions

View file

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

View file

@ -15,7 +15,7 @@ public class Item : ScriptableObject, IComparable<Item> {
public Item(string displayName, string description, int id) {
this.displayName = displayName;
this.description = description;
this._id = id;
_id = id;
}
public int CompareTo(Item other) {

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;