Author Topic: Creating sprite hovering over a territory  (Read 104 times)

potatohead

  • Newbie
  • *
  • Posts: 1
    • View Profile
Creating sprite hovering over a territory
« on: December 07, 2019, 09:10:20 AM »
Is it possible to create a sprite that will hover in the air over a country?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
Re: Creating sprite hovering over a territory
« Reply #1 on: December 13, 2019, 08:22:42 AM »
Hi!

Sure, World Map Strategy Kit includes an example for that. Check out demo sene 001 Standalone, under 2D Map Examples. Run the scene and click "Add Marker (2D Sprite)" button on the right side. A blinking star will appear over a random city.

This is the code:

Code
		/// <summary>
/// Illustrates how to add custom markers over the map using the AddMarker API.
/// In this example a building prefab is added to a random city (see comments for other options).
/// </summary>
void AddMarkerSpriteOnRandomCity () {

// Every marker is put on a plane-coordinate (in the range of -0.5..0.5 on both x and y)
Vector2 planeLocation;

// Add a marker on a random city
City city = map.cities [Random.Range (0, map.cities.Count)];
planeLocation = city.unity2DLocation;

// or... choose a city by its name:
// int cityIndex = map.GetCityIndex("Moscow");
// planeLocation = map.cities[cityIndex].unity2DLocation;

// or... use the centroid of a country
// int countryIndex = map.GetCountryIndex("Greece");
// planeLocation = map.countries[countryIndex].center;

// Send the prefab to the AddMarker API setting a scale of 0.02f (this depends on your marker scales)
GameObject star = Instantiate (Resources.Load<GameObject> ("Sprites/StarSprite"));
map.AddMarker2DSprite (star, planeLocation, 0.02f);

// Optionally: Fly to the destination and see the building created
map.FlyToLocation (planeLocation);

// Optionally: Add a blinking effect to the marker
MarkerBlinker.AddTo (star, 3, 0.2f);
}

Regards