Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

I can't see the object I created via C# unless I click on it in the hierarchy.

Discussion in 'Editor & General Support' started by Asusralis, Oct 27, 2016.

  1. Asusralis

    Asusralis

    Joined:
    Oct 27, 2016
    Posts:
    11
    Video of it here. The object exists and updates, but it doesn't draw unless you click on it in the hierarchy.

    Code:
    Code (CSharp):
    1.     GameObject ball = new GameObject("Fireball");
    2.  
    3.     ball.transform.position = owner.transform.position;
    4.  
    5.     // Set up projectile and calculate direction.
    6.     Projectile projectile = ball.AddComponent<Projectile>();
    7.     projectile.Speed = 1f;
    8.  
    9.     Vector2 delta = owner.transform.position -
    10.         Camera.main.ScreenToWorldPoint(Input.mousePosition);
    11.  
    12.     float radians = Mathf.Atan2(delta.y, delta.x);
    13.  
    14.     projectile.Direction = new Vector2(
    15.         Mathf.Cos(radians),
    16.         Mathf.Sin(radians));
    17.  
    18.     // Set up mesh.
    19.     QuickPolygon poly = ball.AddComponent<QuickPolygon>();
    20.  
    21.     poly.SetMeshType(MeshType.Circle);
    22.     poly.SetBorderUnicolor(new Color32(255, 0, 0, 255), .03f);
    23.     poly.SetFillEmpty();
    24.     poly.SetBorderColor(new Color32(255, 0, 0, 255));
    25.  
    26.     poly.RecalculateMesh();
    QuickPoly is a wrapper for OpenGL primitives.
     
unityunity