mirror of
https://github.com/ConjureETS/Bomberman.git
synced 2026-03-24 10:20:58 +00:00
31 lines
930 B
C#
31 lines
930 B
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
[RequireComponent(typeof(PlayerInput))]
|
|
public class Player : MonoBehaviour {
|
|
public GameObject labelPrefab;
|
|
public GameObject bombPrefab;
|
|
|
|
Arena arena;
|
|
int strength = 1;
|
|
|
|
void Awake() => arena = GameObject.Find("Arena").GetComponent<Arena>();
|
|
|
|
void Start() {
|
|
Transform canvas = GameObject.Find("Canvas").transform;
|
|
PlayerLabel label = Instantiate(labelPrefab, canvas).GetComponent<PlayerLabel>();
|
|
|
|
var playerInput = GetComponent<PlayerInput>();
|
|
|
|
label.player = transform;
|
|
label.SetName(gameObject.name);
|
|
label.SetController(playerInput.currentControlScheme);
|
|
|
|
playerInput.actions["Place"].performed += OnPlace;
|
|
}
|
|
|
|
void OnPlace(InputAction.CallbackContext ctx) {
|
|
var bomb = Instantiate(bombPrefab, arena.GetClosestTilePos(transform.position) - Vector3.up * 0.5f, bombPrefab.transform.rotation);
|
|
bomb.GetComponent<Bomb>().Init(strength, arena);
|
|
}
|
|
} |