-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerController.cs
37 lines (32 loc) · 1.01 KB
/
PlayerController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class PlayerController : MonoBehaviour
{
[SerializeField] Tilemap ground;
[SerializeField] Sprite placeable;
[SerializeField] GameObject turretTemplate;
[SerializeField] Camera cam;
List<Vector3Int> towers = new List<Vector3Int>();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonUp(0))
{
var pos = cam.ScreenToWorldPoint(Input.mousePosition);
var cell = ground.WorldToCell(pos);
if (ground.GetSprite(cell) == placeable && !towers.Contains(cell))
{
var turret = Instantiate(turretTemplate);
turret.transform.position = ground.CellToWorld(cell) + new Vector3(0.5f, 0.5f, 0); ;
turret.SetActive(true);
towers.Add(cell);
}
}
}
}