Skip to content

Instantly share code, notes, and snippets.

@DennisMac
Created February 17, 2018 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DennisMac/3a0fa00c0251524ac8176dff8f10e96c to your computer and use it in GitHub Desktop.
Save DennisMac/3a0fa00c0251524ac8176dff8f10e96c to your computer and use it in GitHub Desktop.
Space Fighter Radar
void FixedUpdate()
{
if (target == null)
{
Destroy(this.gameObject);
return;
}
Vector3 radarPos = (target.position - player.position).normalized;
radarPos = Quaternion.Inverse(player.rotation) * radarPos;
float x = radarPos.x * 50f;
float y = 50 + radarPos.y * 50f;
if (radarPos.z > 0)
{
image.sprite = solidBlip;
}
else
{
image.sprite = hollowBlip;
}
image.rectTransform.localPosition = new Vector3(x, y, image.rectTransform.position.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment