Quest compasses are common to RPG games, but not traditional adventures that AC is designed for.
It can be done through scripting, however, by reading the angle between each Hotspot's relative position to the camera, and the camera's facing direction.
Here's a sample script that uses this to draw icons using Unity's ImGUI system. You'll probably want to rely on Unity UI in practice, but this'll give you a head-start:
using UnityEngine;
using AC;
public class HotspotCompass : MonoBehaviour
{
public float maxAngle = 50f;
public float iconSize = 0.05f;
public float iconY = 0.9f;
public Texture2D iconTexture;
public Texture2D backgroundTexture;
public float barWidth = 0.3f;
private void OnGUI ()
{
if (backgroundTexture)
{
Rect backgroundRect = AdvGame.GUIRect (0.5f, 1f - iconY, barWidth, iconSize);
GUI.DrawTexture (backgroundRect, backgroundTexture, ScaleMode.StretchToFill, true, 0f);
}
if (iconTexture == null)
{
return;
}
foreach (Hotspot hotspot in KickStarter.stateHandler.Hotspots)
{
if (!hotspot.IsOn ())
{
continue;
}
Vector3 relativePosition = hotspot.transform.position - Camera.main.transform.position;
relativePosition.y = 0f;
Vector3 cameraForward = Camera.main.transform.forward;
cameraForward.y = 0f;
float angle = Vector3.SignedAngle (cameraForward, relativePosition, Vector3.up);
angle = Mathf.Clamp (angle, -maxAngle, maxAngle);
float centreAmount = ((angle / maxAngle) + 1f) * 0.5f;
float iconX = (centreAmount * barWidth) + ((1f - barWidth) / 2f);
Rect rect = AdvGame.GUIBox (new Vector2 (iconX * Screen.width, iconY * Screen.height), iconSize);
GUI.DrawTexture (rect, iconTexture, ScaleMode.ScaleToFit, true, 0f);
}
}
}
Comments
Quest compasses are common to RPG games, but not traditional adventures that AC is designed for.
It can be done through scripting, however, by reading the angle between each Hotspot's relative position to the camera, and the camera's facing direction.
Here's a sample script that uses this to draw icons using Unity's ImGUI system. You'll probably want to rely on Unity UI in practice, but this'll give you a head-start:
Thank you very much! The script you gave me works perfect!