//------------------------------------------------------------------------- #region Collectible (health for now) /// <summary> /// Sets a new collectible onto a tile /// </summary> public void SetNewCollectibleTile() { if (_collectible != null) { _collectible._currentTile._hCollectible = null; Destroy(_collectible.gameObject); } int height = Random.Range(0, mapHeight - 1), width = Random.Range(0, mapWidth - 1); Debug.LogWarning(mapHeight + " " + height + " " + mapWidth + " " + width); Tile t = Tiles[width, height]; while (t.IsOccupied) { height = Random.Range(0, mapHeight - 1); width = Random.Range(0, mapWidth - 1); t = Tiles[width, height]; } Vector3 newPos = new Vector3(t.transform.position.x, healingCollectiblePrefab.transform.position.y, t.transform.position.z); _collectible = Instantiate(healingCollectiblePrefab, newPos, Quaternion.identity) as HealingCollectible; _collectible._currentTile = t; t._hCollectible = _collectible; }
public void ShowCollectible(HealingCollectible c) { if (_currentStats != c.gameObject) { RemoveStats(); _currentStats = c.gameObject; Transform canvas = GameObject.Find("Canvas").transform; string statsString = "Potion" + "\nGive " + c.healthGiven + " health."; InstantiatePanel(statsString, canvas); } }
void Update() { // if path has been calculated if (_hasPath) { // if end node attained if (!_goalAttained) { if ((pathList.Count > counter && _endNode == pathList[pathList.Count - 1])) { bool tileCollision = false; player.ArriveAndLookWhereYoureGoing(pathList[counter].transform.position); //Check for tile collision Collider[] collisionArray = Physics.OverlapSphere(player.transform.position, 0.05f); for (int i = 0; i < collisionArray.Length; i++) { // Check if arrived if (collisionArray[i].GetComponent(typeof(Tile)) == _endNode) { GoalAttained = true; if (_endNode._hCollectible != null) { HealingCollectible hc = _endNode._hCollectible; stats.GiveHealth(hc.healthGiven); TileGenerator.Instance.SetNewCollectibleTile(); } } else if (collisionArray[i].GetComponent(typeof(Tile)) == pathList[counter]) { tileCollision = true; } player.SetCurrentTile(pathList[counter]); } if (_goalAttained || tileCollision) { counter++; } } else { // CalculateNewPath(); } } // if not in the middle of the end node else if (!_middleOfTheNodeAttained) { if (GoToMiddleOfTile(counter)) { _middleOfTheNodeAttained = true; _hasPath = false; if (_animator != null) { _animator.SetBool("Walk", false); } if (OnReachEnd != null) { OnReachEnd(); } } } } }