public IEnumerator SpawnGangMemberTest() { // create a new gameobject and add the tileinteraction object GameObject gameObject = new GameObject(); gameObject.AddComponent <TileInteraction>(); TileInteraction tileInteractionTest = gameObject.GetComponent <TileInteraction>(); //Assign // create a gangmember object GameObject testGangMember = Resources.Load("Animator/gooseani1_0") as GameObject; // set it tileInteractionTest.SetGangMemberSprite(testGangMember); tileInteractionTest.CreateGangMember(); // skip one frame yield return(null); //Action - retrieve the spawned gangMember GameObject SpawnedGangMember = GameObject.FindGameObjectWithTag("GangMember") as GameObject; //Assert Assert.NotNull(SpawnedGangMember); }
/// <summary> /// Creates a Map of given size and populates it with Tiles and a random PVCTile. /// </summary> /// <param name="width">The width of the map.</param> /// <param name="height">The height of the map.</param> /// <param name="sprites">The sprites to draw the map with.</param> /// <param name="tilePrefab">The prefab to use for creating tiles as GameObjects.</param> /// <param name="gangMemberSprite">The sprite to use to represent gang members.</param> public Map(int width, int height, Sprite[] sprites, GameObject tilePrefab, GameObject gangMemberSprite) { // Initialise the map this.tilePrefab = tilePrefab; this.size = width * height; this.gangMemberSprite = gangMemberSprite; this.width = width; this.height = height; // Create the arrays to store the Tiles and correponding GameObjects tiles = new Tile[size]; tileObjects = new GameObject[size]; // Create an object to hold all of the map tiles GameObject mapPivot = new GameObject(); mapPivot.name = "Map Pivot"; mapPivot.transform.position = new Vector3(0.0f, 0.0f, 0.0f); // Create the map for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Instantiate the new tile GameObject gob = GameObject.Instantiate <GameObject>(tilePrefab) as GameObject; gob.name = "tile_" + x + "x" + y; gob.transform.parent = mapPivot.transform; // Get the renderer and set the tile sprite SpriteRenderer rend = gob.GetComponent <SpriteRenderer>(); rend.sprite = sprites[x + (y * width)]; // Set the tile position gob.transform.localPosition = new Vector3((0.75f * x), -(0.75f * y), 0.0f); // Add the interaction script to the tile TileInteraction interact = gob.AddComponent <TileInteraction>() as TileInteraction; // Set the sprite to use for gang members interact.SetGangMemberSprite(gangMemberSprite); // Create a new Tile object to hold the properties of this tile Tile tile = new Tile(x + (y * width), gob); tile.x = x; tile.y = y; tiles[x + (y * width)] = tile; tileObjects[x + (y * width)] = gob; // Set the tile property of the TileInteraction component interact.tile = tile; } } // Set the maximum width and height positions of the camera GameObject.FindGameObjectWithTag("MainCamera").transform.parent.gameObject.GetComponent <MapCamera>().SetMaxCoord(0.75f * width, 0.75f * height); // Create a PVC tile //generatePVC(); }