Posts

Showing posts from October, 2017

How to set up a world map mouse over highlighting effect using C# in Uinty 3D

Image
The main idea:
The ability to mouse over an item in a game and have a highlighter placed at that position. (clicking or selecting the item will be covered at a different time)

The outcome: (Method 2 shown)

Art assets from the video can be found here: mapflaghighlighter

Method 1:
This uses a Coroutine on game start to create a ray from the mouse position and compares it to a Unity Tag name. Where the highlighter can then be placed. The highlighter only moves from its current position when the ray hits a different positions.

/// This is the good enough way: /// where you dont need an array, only to make sure you set the Tag of all the items in Unity. IEnumerator GetPointsM1() { while (true) { yield return new WaitForSeconds(waitTime); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { //Debug.DrawLine(ray.origin, hit.point); if( hit.transform.tag …