Created
February 17, 2018 14:27
-
-
Save DennisMac/3a0fa00c0251524ac8176dff8f10e96c to your computer and use it in GitHub Desktop.
Space Fighter Radar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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