UI and enemy movement
This commit is contained in:
@@ -58,7 +58,9 @@ public abstract class Character : MonoBehaviour
|
||||
{
|
||||
var leftCheck = GetMapElement(Vector2.left);
|
||||
var rightCheck = GetMapElement(Vector2.right);
|
||||
|
||||
|
||||
//print($"LeftCheck:{leftCheck} right:{rightCheck}");
|
||||
|
||||
isAllowLeft = !(leftCheck == MapElementType.Wall || leftCheck == MapElementType.BreakableWall);
|
||||
isAllowRight = !(rightCheck == MapElementType.Wall || rightCheck == MapElementType.BreakableWall);
|
||||
|
||||
@@ -129,7 +131,7 @@ public abstract class Character : MonoBehaviour
|
||||
if (direction == Vector2.down)
|
||||
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x + direction.x / 2, _capsuleCollider.bounds.min.y - 0.1f);
|
||||
else
|
||||
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x, _capsuleCollider.bounds.min.y + 0.05f);
|
||||
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x, _capsuleCollider.bounds.min.y + 0.1f);
|
||||
var boundsSize = new Vector2(_capsuleCollider.bounds.size.x - 0.05f, 0.1f);
|
||||
|
||||
var raycastHit = Physics2D.BoxCast(rayStartPoint, boundsSize, 0f, direction, 0.1f, _mapLayer);
|
||||
|
||||
@@ -8,6 +8,8 @@ public class Chest : MonoBehaviour
|
||||
private TreasureSO _treasureSO;
|
||||
|
||||
private Transform _treasureObject;
|
||||
private bool _isOpen=false;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -20,8 +22,9 @@ public class Chest : MonoBehaviour
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
var player=collider.GetComponent<Player>();
|
||||
if (player != null)
|
||||
if (player != null && !_isOpen)
|
||||
{
|
||||
_isOpen = true;
|
||||
animator.SetTrigger("OpenChest");
|
||||
switch (_treasureSO.Treasure)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ public class EnemyAI : Character
|
||||
{
|
||||
protected override void OnDeath()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void SetClimbingAnimation(bool isClimbing)
|
||||
@@ -19,7 +18,7 @@ public class EnemyAI : Character
|
||||
{
|
||||
float horizontal = 0;
|
||||
float vertical = 0;
|
||||
|
||||
|
||||
if (Player.Instance.transform.position.x - transform.position.x < -0.05f && isAllowLeft)
|
||||
{
|
||||
horizontal = -1;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
|
||||
public class Player : Character
|
||||
{
|
||||
[SerializeField]
|
||||
@@ -18,6 +22,9 @@ public class Player : Character
|
||||
|
||||
private int _totalCoins = 0;
|
||||
private bool _hasKey = false;
|
||||
|
||||
public int TotalCoins => _totalCoins;
|
||||
|
||||
public static Player Instance { get; private set; }
|
||||
|
||||
private GameObject _hammer;
|
||||
@@ -25,6 +32,8 @@ public class Player : Character
|
||||
private bool _isHoldingHammer = true;
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
|
||||
public event EventHandler<TreasureType> OnPlayerTakeItem;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
@@ -44,11 +53,13 @@ public class Player : Character
|
||||
public void AddCoin()
|
||||
{
|
||||
_totalCoins++;
|
||||
OnPlayerTakeItem?.Invoke(this,TreasureType.Coin);
|
||||
print($"player have {_totalCoins} coins");
|
||||
}
|
||||
|
||||
public void SetKey()
|
||||
{
|
||||
OnPlayerTakeItem?.Invoke(this, TreasureType.Key);
|
||||
print($"player have key");
|
||||
_hasKey = true;
|
||||
}
|
||||
@@ -121,3 +132,4 @@ public class Player : Character
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class UiManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _totalCoins;
|
||||
[SerializeField]
|
||||
private GameObject _keyIcon;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Player.Instance.OnPlayerTakeItem += Instance_OnPlayerTakeItem;
|
||||
}
|
||||
|
||||
private void Instance_OnPlayerTakeItem(object sender, TreasureType e)
|
||||
{
|
||||
switch(e)
|
||||
{
|
||||
case TreasureType.Coin:
|
||||
_totalCoins.text = Player.Instance.TotalCoins.ToString();
|
||||
break;
|
||||
case TreasureType.Key:
|
||||
_keyIcon.SetActive(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff6c3960de97db14f89d6633159838dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user