Add player controller, state management, and input handling
- Implemented PlayerController.cs to manage player movement and actions. - Created PlayerState.cs to track player lives, coins, and key status. - Added CameraFollow.cs for smooth camera movement following the player. - Developed Character.cs as an abstract class for character behavior. - Introduced Enums.cs for defining TreasureType and MapElementType. - Added IDoor interface for door interactions. - Created InputActions.cs for handling player input actions. - Implemented MainMenu.cs for basic menu functionality including play and exit options.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemySpawner : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject _prefab;
|
||||
|
||||
[SerializeField]
|
||||
private int _maxCharacters=1;
|
||||
|
||||
[SerializeField]
|
||||
private Transform _spawnPoint;
|
||||
|
||||
private int _respawnTimeout = 4;
|
||||
private float _respawnElementTimer;
|
||||
|
||||
private List<Character> _characters;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
if(_spawnPoint==null)
|
||||
{
|
||||
_spawnPoint=gameObject.transform;
|
||||
}
|
||||
_characters=new List<Character>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if(_characters.Count<_maxCharacters)
|
||||
{
|
||||
_respawnElementTimer -= Time.deltaTime;
|
||||
if (_respawnElementTimer <= 0)
|
||||
{
|
||||
_respawnElementTimer = _respawnTimeout;
|
||||
var prefab= Instantiate(_prefab, _spawnPoint.position, _spawnPoint.rotation);
|
||||
var character=prefab.GetComponent<Character>();
|
||||
character.OnCharacterDeath+=OnCharacterDeath;
|
||||
|
||||
_characters.Add(character);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCharacterDeath(object sender, EventArgs e)
|
||||
{
|
||||
var character=(sender as Character);
|
||||
character.OnCharacterDeath-=OnCharacterDeath;
|
||||
_characters.Remove(character);
|
||||
Destroy(character.gameObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user