-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameManager.cs
58 lines (52 loc) · 1.67 KB
/
gameManager.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gameManager : MonoBehaviour {
public static bool buildingSelected = false;
public static GameObject currSelectedBuilding;
[SerializeField]
private Canvas cityCenterUI;
[SerializeField]
private GameObject spawnPrefab;
private GameObject currentPlaceableObject;
private int spawnFlagCount = 0;
// Update is called once per frame
void Update () {
if (buildingSelected == true)
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
if(currSelectedBuilding.name != hitInfo.transform.name)
{
currSelectedBuilding.GetComponent<Outline>().enabled = !currSelectedBuilding.GetComponent<Outline>().enabled;
if (currSelectedBuilding.GetComponent<Outline>().enabled == false)
{
// hide ui
cityCenterUI.GetComponent<Canvas>().enabled = false;
buildingSelected = false;
currSelectedBuilding.GetComponent<buildingClick>().updateSpawnLocation();
Destroy(GameObject.Find("shovel(Clone)"));
Destroy(currentPlaceableObject);
}
}
}
}
if (Input.GetMouseButtonDown(1))
{
Destroy(GameObject.Find("shovel(Clone)"));
currentPlaceableObject = Instantiate(spawnPrefab);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
currentPlaceableObject.transform.position = hitInfo.point;
currentPlaceableObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
}
}
}
}
}