public bool BuildTower(TowerBase obj) { if (tower || !obj || playerInside || EnemySpawner.CalculateAI(parent, coords.y, coords) == null) { return(false); } tower = Instantiate(obj, transform); EventBus.Post(new EventWorldChanged(parent)); return(true); }
private void Update() { tick++; if (tick - tickPinged > 2 || playerInside) { return; } if (GameManager.Instance?.Phase != GamePhase.BUILD) { return; } if (!player.destroyTool && this.tower) { return; } RadioSelect select = RadioSelect.Controller.GetSelection("BuildMenu.SelectedTower"); GameObject tower = null; int cost = 0; if (player.destroyTool && this.tower) { tower = this.tower.gameObject; } else if (!player.destroyTool && select && select.additionalData is TowerBase) { tower = (select.additionalData as TowerBase).gameObject; cost = (select.additionalData as TowerBase).towerCost; } if (!tower) { return; } Material mat = player.destroyTool ? destroyOutline : buildOutline; if (cost > player.coins && cantBuildOutline) { mat = cantBuildOutline; } if (!player.destroyTool && EnemySpawner.CalculateAI(parent, coords.y, coords) == null) { mat = cantBuildOutline; } Debug.Assert(mat, "No material specified on " + name); foreach (MeshRenderer render in tower.GetComponentsInChildren <MeshRenderer>()) { if (!render.enabled) { continue; } MeshFilter filter = render.GetComponent <MeshFilter>(); if (filter) { Vector3 position = render.transform.position; Quaternion rotation = render.transform.rotation; Vector3 scale = render.transform.lossyScale; if (!player.destroyTool) { scale.Scale(transform.lossyScale); position.Scale(scale); position = transform.position + position; rotation = transform.rotation * rotation; } Matrix4x4 matrix = Matrix4x4.TRS(position, rotation, scale + Vector3.one * 0.01F); Graphics.DrawMesh(filter.sharedMesh, matrix, mat, gameObject.layer); } } }