Hello everyone reading this.
I hope someone knows how to crack this!
I use a Raycast that makes my enemies(asteroids) HealthUI pop up.
When my players Raycast deselects the asteroid, my UI disables which is perfect.
BUT: When I go select an asteroid after another asteroid (with no space in between) the UI of the previous asteroid stays on screen. I tried a lot of things. But obviously just not the right thing.
Here’s my script:
public Transform brickPlayer;
public LineRenderer lineRenderer;
public LayerMask mask;
private AsteroidUI1 AsteroidUI;
public Transform NewHitObject;
void FixedUpdate()
{
Ray ray = new Ray (transform.position, transform.forward);
RaycastHit hitInfo;
if (Physics.Raycast (ray, out hitInfo, mask))
{
Debug.DrawLine (ray.origin, hitInfo.point, Color.red);
NewHitObject = hitInfo.collider.transform;
if (hitInfo.collider.tag == "Asteroid")
{
lineRenderer.SetPosition (0, brickPlayer.position);
lineRenderer.SetPosition (1, hitInfo.point);
lineRenderer.enabled = true;
ShowAsteroidUI ();
}
}
else
{
if (NewHitObject == true)
{
StopShowAsteroidUI ();
}
Debug.DrawLine (ray.origin, ray.origin + ray.direction * 100, Color.green);
lineRenderer.enabled = false;
}
}
public void ShowAsteroidUI()
{
NewHitObject.GetComponent<AsteroidUI1> ().ShowUI ();
}
public void StopShowAsteroidUI()
{
NewHitObject.GetComponent<AsteroidUI1> ().StopShowUI ();
}