Skip to content

Instantly share code, notes, and snippets.

@icywind
Created March 23, 2020 23:36
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 icywind/f84b5faa3c60d8efdcaa3339920f6e17 to your computer and use it in GitHub Desktop.
Save icywind/f84b5faa3c60d8efdcaa3339920f6e17 to your computer and use it in GitHub Desktop.
Method to draw the dots from the given position
int dotCount = 0;
/// <summary>
///
/// </summary>
/// <param name="pos">Screen Position</param>
void DrawDot(Vector2 pos)
{
if (anchorGO == null)
{
anchorGO = new GameObject();
anchorGO.transform.SetParent(referenceObject.transform.parent);
anchorGO.transform.position = Vector3.zero;
anchorGO.transform.localScale = Vector3.one;
anchorGO.name = "DrawAnchor";
}
// DeNormalize the position and adjust to passed camera
Vector3 location = DeNormalizedPosition(pos, renderCam);
GameObject go = GameObject.Instantiate(DrawPrefab, location, Quaternion.identity);
go.transform.SetParent(anchorGO.transform);
go.transform.localScale = DotScale * Vector3.one;
go.layer = (int)CameraLayer.IGNORE_RAYCAST;
go.name = "dot " + dotCount;
dotCount++;
Debug.LogFormat("{0} pos:{1} => : {2} ", go.name, pos, location);
Renderer renderer = go.GetComponent<Renderer>();
if (renderer != null)
{
Material mat = renderer.material;
if (mat != null)
{
mat.color = DrawColor;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment