Search Unity

  1. 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

Linerenderer positions from Transform

Discussion in 'Scripting' started by Achim, Jan 21, 2011.

  1. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    i tried to a modify a script from the forum to get the Linerenderers positions from Transforms but get an error when compiling:

    Code (csharp):
    1. // the options
    2. var startWidth = 0.05;
    3. var endWidth = 0.05;
    4. var aMaterial : Material;
    5.  
    6.  
    7.  
    8. // these are set in start
    9. private var line : LineRenderer;
    10.  
    11. var point01 : Transform;
    12. var point02 : Transform;
    13. var point03 : Transform;
    14. var point04 : Transform;
    15. var point05 : Transform;
    16.  
    17.  
    18. function Start ()
    19. {
    20.    line = this.gameObject.AddComponent(LineRenderer);
    21.    line.SetWidth(startWidth, endWidth);
    22.    line.SetVertexCount(5);
    23.    line.material = aMaterial;
    24.    //line.renderer.enabled = true;
    25. }
    26.  
    27. function Update ()
    28. {
    29.    line.SetPosition(0, point01);
    30.    line.SetPosition(1, point02);
    31.    line.SetPosition(2, point03);
    32.    line.SetPosition(3, point04);
    33.    line.SetPosition(4, point05);
    34. }
    35.  
    36.  
    how can i get the point positions from transforms or gameobjects ?
     
  2. sccrstud92

    sccrstud92

    Joined:
    Jan 20, 2011
    Posts:
    145
    The SetPosition function doesn't want a Transform object. It wants a Vector3 (a position). The fix is really easy.

    Instead of
    Code (csharp):
    1. line.SetPosition(0, point01);
    use
    Code (csharp):
    1. line.SetPosition(0, point01.position);
    If you do that for all the SetPosition calls, it should work great.
     
  3. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    thanks a lot,now it works
     
unityunity