private void Awake() { pathable = GetComponent <Pathable>(); grabbable = GetComponent <Grabbable>(); animator = GetComponentInChildren <Animator>(); pathable.OnPathingStateChanged += PathingStateChanged; }
public Grabbable GrabNewWolf() { GameObject go = Instantiate(wolfPrefab); grabbed = go.GetComponent <Grabbable>(); // spend the energy player.energy -= PlayerStats.costWolf; overlayController.SetEnergyValue(player.energy); // don't show it until the player hovers over the map go.transform.position = new Vector3(-1000, -1000f, -1000f); grabbed.Grabbed = true; return(grabbed); }
public Grabbable GrabNewGoat() { /* if (grabbed != null) * { * Destroy(grabbed.gameObject); * grabbed = null; * }*/ GameObject go = Instantiate(goatPrefab); grabbed = go.GetComponent <Grabbable>(); // spend the energy player.energy -= PlayerStats.costGoat; overlayController.SetEnergyValue(player.energy); // don't show it until the player hovers over the map go.transform.position = new Vector3(-1000, -1000f, -1000f); grabbed.Grabbed = true; return(grabbed); }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { EnableEscMenu(!Paused); } else if (!Paused) { // place something if (grabbed != null) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, LayerMask.GetMask("Terrain"))) { Vector3 placePosition = hit.point; grabbed.transform.position = placePosition; if (Input.GetMouseButtonDown(0)) { HexTile tile = GetTileAtMousePosition(); if (tile != null) { ///TODO Clean this up Goat goat = grabbed.GetComponent <Goat>(); if (goat != null) { goats.Add(goat); UpdatePotentialEnergy(); } Cow cow = grabbed.GetComponent <Cow>(); if (cow != null) { cows.Add(cow); UpdatePotentialEnergy(); } Wolf wolf = grabbed.GetComponent <Wolf>(); if (wolf != null) { wolves.Add(wolf); UpdatePotentialEnergy(); } grabbed.Grabbed = false; grabbed = null; } } } else { if (Input.GetMouseButtonDown(0)) { // operation was cancelled Destroy(grabbed.gameObject); grabbed = null; } } } else if (IsExpansionMode) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, LayerMask.GetMask("Terrain"))) { Vector3 placePosition = hit.point; if (Input.GetMouseButtonDown(0)) { HexTile tile = GetTileAtMousePosition(); if (tile != null) { if (tile.IsEmpty) { HexTile.MaterialEnum material = (terrain.TileCount < 9) ? HexTile.MaterialEnum.Grass : HexTile.MaterialEnum.Rock; terrain.SetTile(tile.tilePosition, material); SetExpansionMode(false); } } } } } else { if (Input.GetMouseButtonDown(0)) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f)) { Goat goat = hit.collider.gameObject.GetComponentInParent <Goat>(); if (goat != null && goats.Contains(goat)) { // consume the goat player.energy += PlayerStats.potentialEnergyGoat; overlayController.SetEnergyValue(player.energy); // using the single dead function here // may want to also have a sacrifice animation goat.GotDead(); } Cow cow = hit.collider.gameObject.GetComponentInParent <Cow>(); if (cow != null && cows.Contains(cow)) { // consume the cow player.energy += PlayerStats.potentialEnergyCow; overlayController.SetEnergyValue(player.energy); // kill the cow cow.GotDead(); } Wolf wolf = hit.collider.gameObject.GetComponentInParent <Wolf>(); if (wolf != null && wolves.Contains(wolf)) { // consume the cow player.energy += PlayerStats.potentialEnergyWolf; overlayController.SetEnergyValue(player.energy); // kill the cow wolf.GotDead(); } } } } } }