Refactor player and enemy scripts; remove unused classes and improve initialization
- Added base initialization call in PlayerController. - Changed player reference in EnemyAI to be serialized for better inspector visibility. - Ensured characters are initialized upon spawning in EnemySpawner. - Removed obsolete EnemyAI and Chest scripts to streamline codebase. - Added KeyChest script for key collection functionality. - Introduced new meta files for better organization and tracking. - Created launch configuration for Unity debugging.
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : Character
|
||||
{
|
||||
[SerializeField]
|
||||
private Sprite _regularSprite;
|
||||
[SerializeField]
|
||||
private Sprite _noHammerSprite;
|
||||
|
||||
private GameObject _hammer;
|
||||
|
||||
private bool _isHoldingHammer = true;
|
||||
|
||||
public event EventHandler<TreasureType> OnPlayerTakeItem;
|
||||
|
||||
private InputManager _inputManager;
|
||||
private PlayerState _playerState;
|
||||
private HammerThrower _hammerThrower;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_inputManager = GetComponent<InputManager>();
|
||||
_playerState = GetComponent<PlayerState>();
|
||||
_hammerThrower = GetComponent<HammerThrower>();
|
||||
|
||||
_inputManager.OnFire += OnFireButtonPressed;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_inputManager.OnEnable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_inputManager.OnDisable();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_hammer == null && !_isHoldingHammer)
|
||||
{
|
||||
_spriteRenderer.sprite = _regularSprite;
|
||||
_isHoldingHammer = true;
|
||||
}
|
||||
|
||||
Vector2 move = _inputManager.Movement;
|
||||
MoveTo(move.x, isAllowVertical ? move.y : 0);
|
||||
_hammerThrower.SetFacingDirection(_facingRight);
|
||||
}
|
||||
|
||||
private void OnFireButtonPressed()
|
||||
{
|
||||
if (_hammerThrower.CanThrow)
|
||||
{
|
||||
_animator.SetTrigger("Body_ThrowHammer");
|
||||
}
|
||||
}
|
||||
|
||||
// Animation event
|
||||
public void ThrowHammerObject()
|
||||
{
|
||||
_hammerThrower.TryThrowHammer();
|
||||
UpdatePlayerSprite();
|
||||
}
|
||||
|
||||
private void UpdatePlayerSprite()
|
||||
{
|
||||
_spriteRenderer.sprite = _hammerThrower.HasHammer
|
||||
? _regularSprite
|
||||
: _noHammerSprite;
|
||||
}
|
||||
protected override void SetWalkingAnimation(bool isWalking)
|
||||
{
|
||||
_bonesBack.SetActive(false);
|
||||
_bonesSide.SetActive(true);
|
||||
_animator.SetBool("Legs_Walk", isWalking);
|
||||
_animator.SetBool("Body_Walk", isWalking);
|
||||
}
|
||||
|
||||
protected override void SetClimbingAnimation(bool isClimbing)
|
||||
{
|
||||
if (isClimbing)
|
||||
{
|
||||
_bonesBack.SetActive(true);
|
||||
_bonesSide.SetActive(false);
|
||||
}
|
||||
_animator.SetBool("Climb", isClimbing);
|
||||
}
|
||||
|
||||
protected void OnDeath()
|
||||
{
|
||||
_playerState.Lives--;
|
||||
|
||||
if (_playerState.Lives == 0)
|
||||
{
|
||||
Debug.Log("Game over");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c83b0150e991b443858a82f5a1eea57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user