fixing fire system

This commit is contained in:
2023-06-28 22:53:31 +03:00
parent 251308ce6a
commit dc770b49af
10 changed files with 260 additions and 41 deletions
+5 -5
View File
@@ -12,11 +12,11 @@ public class Character : MonoBehaviour
private Rigidbody2D _body;
private BoxCollider2D _boxCollider;
private bool _isOnBridge;
private bool _isOnLadder;
private bool _isFalling;
private bool _facingRight = true;
protected bool _isOnBridge;
protected bool _isOnLadder;
protected bool _isFalling;
protected bool _facingRight = true;
protected bool isAllowVertical = true;
+6 -4
View File
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hammer : MonoBehaviour
@@ -12,10 +10,14 @@ public class Hammer : MonoBehaviour
private void OnCollisionEnter2D(Collision2D collision)
{
var mapElement = collision.collider.GetComponent<MapElement>();
var mapElement = collision.collider.GetComponent<MapElement>();
if(mapElement!=null)
{
Destroy(gameObject);
}
if (mapElement?.ElementSO.ElementType==MapElementType.BreakableWall)
{
Destroy(collision.gameObject);
mapElement.Hit();
Destroy(gameObject);
}
}
+6 -2
View File
@@ -9,9 +9,13 @@ public class MapElement : MonoBehaviour
private float _respawnElementTimer;
private int _respawnTimeout = 4;
private bool _needRespawn = false;
public void Hit()
{
gameObject.GetComponent<BoxCollider2D>().enabled = false;
gameObject.GetComponent<BoxCollider2D>().enabled=false;
gameObject.GetComponentInChildren<SpriteRenderer>().enabled = false;
_respawnElementTimer = _respawnTimeout;
_needRespawn = true;
}
@@ -24,9 +28,9 @@ public class MapElement : MonoBehaviour
{
_respawnElementTimer = _respawnTimeout;
gameObject.GetComponent<BoxCollider2D>().enabled = true;
gameObject.GetComponentInChildren<SpriteRenderer>().enabled = true;
_needRespawn = false;
}
}
}
}
+10 -7
View File
@@ -7,13 +7,13 @@ public class Player : Character
[SerializeField]
private GameObject _hammerPrefab;
private int _hammerSpeed=10;
private int _hammerSpeed = 10;
private int _totalCoins = 0;
private bool _hasKey = false;
public static Player Instance { get; private set; }
private GameObject _hammer;
private void Awake()
{
@@ -29,7 +29,6 @@ public class Player : Character
DontDestroyOnLoad(gameObject);
}
public void AddCoin()
{
_totalCoins++;
@@ -39,7 +38,7 @@ public class Player : Character
public void SetKey()
{
print($"player have key");
_hasKey =true;
_hasKey = true;
}
public void RemoveKey()
@@ -54,10 +53,14 @@ public class Player : Character
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
if (Input.GetKeyDown(KeyCode.Space) && !_isFalling)
{
var hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation);
hammer.GetComponent<Rigidbody2D>().velocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed,0);
if (_hammer == null)
{
_hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation);
_hammer.transform.localScale = new Vector2(_hammer.transform.localScale.x * (_facingRight ? 1 : -1), _hammer.transform.localScale.y);
_hammer.GetComponent<Rigidbody2D>().velocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed, 0);
}
}
base.MoveTo(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}