2020-06-28 19:12:59 -04:00

27 lines
834 B
C#

using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(PlayerInput))]
public class Player : MonoBehaviour {
public GameObject labelPrefab;
public GameObject bombPrefab;
public Arena 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(1, arena);
}
}