Search Unity

Tron Trail.js error

Discussion in 'iOS and tvOS' started by cherub, Nov 14, 2014.

  1. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    BCE0019: 'point' is not a member of 'Object'.

    works fine in desktop mode. not for iOS

    not sure what do to fix.

    Code (JavaScript):
    1. /*
    2. Generates a trail that is always facing upwards using the scriptable mesh interface.
    3. vertex colors and uv's are generated similar to the builtin Trail Renderer.
    4. To use it
    5. 1. create an empty game object
    6. 2. attach this script and a MeshRenderer
    7. 3. Then assign a particle material to the mesh renderer
    8. */
    9. var dirChange = false;
    10. var height = 2.0;
    11. var brushSize = 1.5f;
    12. public var time = 2.0;
    13. var alwaysUp = false;
    14. var minDistance = 0.1;
    15.  
    16. var startColor = Color.white;
    17. var endColor = Color (1, 1, 1, 0);
    18. var strokeLength = 10f;
    19. var terminate = false;
    20.  
    21. class TronTrailSection
    22. {
    23.     var point : Vector3;
    24.     var upDir : Vector3;
    25.     var time : float;
    26. }
    27.  
    28. private var sections = new Array();
    29.  
    30. var lastPosition : Vector3;
    31. var myDirection : Vector3;
    32.  
    33.  
    34. function LateUpdate () {
    35.     transform.Rotate(0, 0, Time.deltaTime * 200);
    36.     var position = transform.position;
    37.     position.y -= height/2;
    38.     var now = Time.time;
    39.  
    40.  
    41.     // Remove old sections
    42.     //while (sections.length > 0 && now > sections[sections.length - 1].time + time)
    43.     //{
    44.     //    sections.Pop();
    45.     //}
    46.  
    47.     // Add a new trail section
    48.     if (sections.length == 0 || (sections[0].point - position).sqrMagnitude > minDistance * minDistance)
    49.     {
    50.         var section = TronTrailSection ();
    51.  
    52.         section.point = position;
    53.      
    54.         if (alwaysUp)
    55.         {
    56.             if(!dirChange)
    57.                 section.upDir = transform.up ;
    58.             if(dirChange)
    59.                 section.upDir = transform.right;
    60.         }
    61.      
    62.         else
    63.             section.upDir = transform.TransformDirection(Vector3.up);
    64.         section.time = now;
    65.         sections.Unshift(section);
    66.      
    67.                 if(height < brushSize)
    68.             height += 0.05f * brushSize;
    69.     }
    70.  
    71.     // Rebuild the mesh
    72.  
    73.     var mesh : Mesh = GetComponent(MeshFilter).mesh;
    74.     mesh.Clear();
    75.  
    76.     // We need at least 2 sections to create the line
    77.     if (sections.length < 2)
    78.         return;
    79.  
    80.     var vertices = new Vector3[sections.length * 2];
    81.     var colors = new Color[sections.length * 2];
    82.     var uv = new Vector2[sections.length * 2];
    83.  
    84.     var previousSection : TronTrailSection = sections[0];
    85.     var currentSection : TronTrailSection = sections[0];
    86.  
    87.     // Use matrix instead of transform.TransformPoint for performance reasons
    88.     var localSpaceTransform = transform.worldToLocalMatrix;
    89.  
    90.     // Generate vertex, uv and colors
    91.     for (var i=0;i<sections.length;i++)
    92.     {
    93.          
    94.      
    95.         previousSection = currentSection;
    96.         currentSection = sections[i];
    97.      
    98.         var ratio = i * 1f / sections.length;
    99.  
    100.         // Calculate upwards direction
    101.         var upDir = currentSection.upDir;
    102.      
    103.         // Generate vertices
    104.  
    105.         vertices[i * 2 + 0] = localSpaceTransform.MultiplyPoint(currentSection.point - upDir * height);
    106.         vertices[i * 2 + 1] = localSpaceTransform.MultiplyPoint(currentSection.point + upDir * height);
    107.         //vertices[i] = localSpaceTransform.MultiplyPoint(currentSection.point + upDir * height);
    108.      
    109.         //var curDistance = 0.00;
    110.      
    111.         uv[i * 2 + 0] = new Vector2(ratio , 0);
    112.         uv[i * 2 + 1] = new Vector2(ratio, 1);
    113.  
    114.  
    115.         // fade colors out over time
    116.         //var interpolatedColor = Color.Lerp(startColor, endColor, u);
    117.         colors[i * 2 + 0] = startColor;
    118.         colors[i * 2 + 1] = endColor;
    119.     }
    120.  
    121.     if(terminate && sections.length > strokeLength)
    122.     {
    123.         Destroy(this);
    124.     }
    125.     // Generate triangles indices
    126.     var triangles = new int[(sections.length - 1) * 2 * 3];
    127.     for (i=0;i<triangles.length / 6;i++)
    128.     {
    129.         triangles[i * 6 + 0] = i * 2;
    130.         triangles[i * 6 + 1] = i * 2 + 1;
    131.         triangles[i * 6 + 2] = i * 2 + 2;
    132.  
    133.         triangles[i * 6 + 3] = i * 2 + 2;
    134.         triangles[i * 6 + 4] = i * 2 + 1;
    135.         triangles[i * 6 + 5] = i * 2 + 3;
    136.     }
    137.  
    138.     // Assign to mesh  
    139.     mesh.vertices = vertices;
    140.     mesh.colors = colors;
    141.     mesh.uv = uv;
    142.     mesh.triangles = triangles;
    143. }
    144.  
    145. @script RequireComponent (MeshFilter)
    146.  
     
    Last edited: Nov 14, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Put "#pragma strict" at the top. Replace Array with a generic List.

    --Eric
     
  3. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    Thanks. i tried this but now there are many more errors.

    Code (JavaScript):
    1. #pragma strict
    2. import System.Collections.Generic;
    3.  
    4. //private var sections = new Array();
    5. var sections = new List.<Vector3>();
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Fix the errors. ;)

    --Eric
     
  5. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    i fixed most of the errors.

    I am stuck on how to fix these as i am not sure how the class TronTrailSection is being applied

    BCE0019: 'point' is not a member of 'UnityEngine.Vector3'.
    BCE0022: Cannot convert 'UnityEngine.Vector3' to 'TronTrailSection'.

    I am also not sure if the list should be a Vector3?
     
  6. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    got it. i made the list this way:
    Code (JavaScript):
    1. var sections = new List.<TronTrailSection>();
     
    Last edited: Nov 14, 2014