public IEnumerable <GameObject> GetTargetsForShooting() { if (PlayerTank.Instance != null) { // Vector3 pos = PlayerTank.Instance.transform.position; // yield return new Vector2(pos.x, pos.z); yield return(PlayerTank.Instance.gameObject); } if (Flag.Instance != null) { yield return(Flag.Instance.gameObject); // objects around flag Vector2 flagPos = Flag.Instance.Position; foreach (Vector2 posOffset in s_positionsAroundFlag) { Vector2 pos = flagPos + posOffset; if (MapManager.IsInsideMap(pos)) { var mapObj = MapManager.GetMapObjectAt(pos); if (mapObj != null) { yield return(mapObj.gameObject); } } } } // player tank's bullets // foreach (Bullet bullet in Bullet.AllBullets.Where(b => b.TankShooter != null && b.TankShooter == PlayerTank.Instance)) // { // yield return bullet.gameObject; // } }
public bool CanWalkToBlock(Vector2 blockPos) { if (!MapManager.IsInsideMap(blockPos)) { return(false); } var mapObj = MapManager.GetMapObjectAt(blockPos); if (mapObj != null && !mapObj.IsPassable) { return(false); } return(!IsAnyTankAtBlock(blockPos, this)); //return true; }
void SpawnPickup() { // find a place for spawning List <Vector2Int> freePlaces = new List <Vector2Int>(); for (int i = 0; i < MapManager.MapWidth; i++) { for (int j = 0; j < MapManager.MapHeight; j++) { if (null == MapManager.GetMapObjectAt(i, j)) { freePlaces.Add(new Vector2Int(i, j)); } } } if (freePlaces.Count < 1) { return; } // pick a random place Vector2Int pos = freePlaces[Random.Range(0, freePlaces.Count)]; // spawn it var pickup = MapManager.SpawnMapObject(this.pickupPrefab, pos).GetComponent <Pickup>(); // choose type of pickup int index = Random.Range(0, m_pickupActions.Length); // assign material pickup.GetComponent <MeshRenderer>().sharedMaterial = this.pickupMaterials[index]; // assign action on collision pickup.onCollided += m_pickupActions[index]; // destroy pickup when it's lifetime expires Destroy(pickup.gameObject, this.pickupLifeTime); Debug.LogFormat("Spawned pickup {0} at {1}", index, pos); }