Also, any thoughts on how you would actually want to be able use the compass in-game, and how it should work with the inventory?
For my own project, I think it should be an item that can be picked up, and then gives you the option to switch a compass on and off as part of the GUI.
My version would basically be a "use" command on the compass in your inventory. It would stop the player from moving and show the compass up on the screen while you were stopped. You click again and it turns the compass off and you can move again.
Yeah yeah ... I actually wrote most of it, then got distracted.
The funny thing is, I thought of bringing it into my current game project just the other day, but in a slightly changed form. It's a fantasy spoof setting where most people have MHDs (Magical Handheld Devices) as seen in this concept drawing:
Did some slight updates to the original compass on this one but had a scripting question (since I'm basically an idiot). I have two components on the main camera. A rotating UI element (the arrow of the compass) and the non-rotating element (the "frame" of the compass that shows the directions). This seems to work fine, however, I'm starting to think that it doesn't make sense for this to be on the main camera for my game. Arkhangel is a series of static cameras that change via trigger. That means the compass is camera justified and not player...however, if I put it on the player, then I need to make sure there's a way to turn it on/off. I basically only want the compass to be on by default in the "overworld" maps and not the interior sub scenes...unless the player clicks on the compass in the inventory.
What's a straight-forward method of doing that? Should I overhaul how I'm doing this?
If you want to integrate it with inventory clicks, you'll probably want to move it to a Unity UI-based AC Menu, which you can then turn on and off using Actions when the inventory item is interacted with.
If you simply use AC's Menu Manager to link up the Canvas object and set the Appear type to Manual, then you'll be able to control the UI's position and rotation through your own scripts without there being any conflict.
Thanks @ChrisIceBox. How would I feed the player's position into this to the compass would animate based off of what direction the player is pointing? Here's the original code that Mr. @Snebjorn provided awhile ago:
Rect compass_rect =new Rect(screenPositionX, screenPositionY, compassTexture.width, compassTexture.height);
GUI.DrawTexture(compass_rect, compassTexture);
}
}
I was going to try and add a child gameobject to the player and send a message to that to be on/off via the menu system. The wiring is in place, but I'm guessing Send Message doesn't do anything for UI element's visibility. Also tried setting the object up to Remember Visibility and defaulting it off and turning it on via Menu but that didn't work for me either.
Just a quick note about my code: instantiating a new compass_center and compass_rect each time OnGUI() is called is a Really Bad Idea[TM] - they should really be converted to class members instead.
Comments
Just bugging
I'd also allow the player to be able to start moving whIle looking at compass - when the player moves compass automatically disappears.
If you simply use AC's Menu Manager to link up the Canvas object and set the Appear type to Manual, then you'll be able to control the UI's position and rotation through your own scripts without there being any conflict.
using UnityEngine;
using System.Collections;
public class Compass : MonoBehaviour {
public Texture compassTexture;
public float screenPositionX = 50;
public float screenPositionY = 50;
void OnGUI()
{
Vector2 compass_center = new Vector2(screenPositionX + compassTexture.width / 2, screenPositionY + compassTexture.height / 2);
GUIUtility.RotateAroundPivot(-(transform.eulerAngles.y), compass_center);
Rect compass_rect = new Rect(screenPositionX, screenPositionY, compassTexture.width, compassTexture.height);
GUI.DrawTexture(compass_rect, compassTexture);
}
}