Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by bdp · Feb 14, 2012 at 08:44 PM · arraylisttypecastingmember

'time' not a member of 'Object'

I got this from somewhere and I really like it for light trails, but it doesn't play well with #pragma strict. I know in a lot of similar questions that they recommend using List, but I can't use System.Collections.Generic because I don't think it's compatible with iphone/andoid etc. With #pragma strict I get:

'time' not a member of 'Object' and 'point' not a member of 'Object'

Could someone walk me through how to fix this? I'm a little lost, it has to do with dynamic typecasting, right? Thanks a lot.

 #pragma strict
 /*
  Generates a trail that is always facing upwards using the scriptable mesh interface.
  vertex colors and uv's are generated similar to the builtin Trail Renderer.
  To use it
  1. create an empty game object
  2. attach this script and a MeshRenderer
  3. Then assign a particle material to the mesh renderer
 */
 var height = 2.0;
 var time = 2.0;
 var alwaysUp = false;
 var minDistance = 0.1;
 
 var startColor = Color.white;
 var endColor = Color (1, 1, 1, 0);
 
 class TronTrailSection
 {
     var point : Vector3;
     var upDir : Vector3;
     var time : float;
 }
 
 private var sections = new Array();
 
 
 function LateUpdate () {
 
     var position = transform.position;
     var now = Time.time;
 
     // Remove old sections
     while (sections.length > 0 && now > sections[sections.length - 1].time + time) {
         sections.Pop();
     }
 
     // Add a new trail section
     if (sections.length == 0 || (sections[0].point - position).sqrMagnitude > minDistance * minDistance)
     {
         var section = TronTrailSection ();
         section.point = position;
         if (alwaysUp)
             section.upDir = Vector3.up;
         else
             section.upDir = transform.TransformDirection(Vector3.up);
         section.time = now;
         sections.Unshift(section);
     }
     
     // Rebuild the mesh
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     mesh.Clear();
     
     // We need at least 2 sections to create the line
     if (sections.length < 2)
         return;
 
     var vertices = new Vector3[sections.length * 2];
     var colors = new Color[sections.length * 2];
     var uv = new Vector2[sections.length * 2];
     
     var previousSection : TronTrailSection = sections[0];
     var currentSection : TronTrailSection = sections[0];
 
     // Use matrix instead of transform.TransformPoint for performance reasons
     var localSpaceTransform = transform.worldToLocalMatrix;
 
     // Generate vertex, uv and colors
     for (var i=0;i<sections.length;i++)
     {
         previousSection = currentSection;
         currentSection = sections[i];
         // Calculate u for texture uv and color interpolation
         var u = 0.0;        
         if (i != 0)
             u = Mathf.Clamp01 ((Time.time - currentSection.time) / time);
         
         // Calculate upwards direction
         var upDir = currentSection.upDir;
         
         // Generate vertices
         vertices[i * 2 + 0] = localSpaceTransform.MultiplyPoint(currentSection.point);
         vertices[i * 2 + 1] = localSpaceTransform.MultiplyPoint(currentSection.point + upDir * height);
         
         uv[i * 2 + 0] = Vector2(u, 0);
         uv[i * 2 + 1] = Vector2(u, 1);
         
         // fade colors out over time
         var interpolatedColor = Color.Lerp(startColor, endColor, u);
         colors[i * 2 + 0] = interpolatedColor;
         colors[i * 2 + 1] = interpolatedColor;
     }
 
     // Generate triangles indices
     var triangles = new int[(sections.length - 1) * 2 * 3];
     for (i=0;i<triangles.length / 6;i++)
     {
         triangles[i * 6 + 0] = i * 2;
         triangles[i * 6 + 1] = i * 2 + 1;
         triangles[i * 6 + 2] = i * 2 + 2;
 
         triangles[i * 6 + 3] = i * 2 + 2;
         triangles[i * 6 + 4] = i * 2 + 1;
         triangles[i * 6 + 5] = i * 2 + 3;
     }
 
     // Assign to mesh    
     mesh.vertices = vertices;
     mesh.colors = colors;
     mesh.uv = uv;
     mesh.triangles = triangles;
     
 }
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessy · Feb 14, 2012 at 09:00 PM 0
Share

" but I can't use System.Collections.Generic because I don't think it's compatible with iphone/andoid etc." Come on now; that hasn't been the case for years. It's ridiculous to have gone with that belief ins$$anonymous$$d of finding out for sure.

avatar image bdp · Feb 14, 2012 at 09:26 PM 0
Share

Oh really? I assumed that was the case. I read about someone having trouble with it on iphone and didn't want to risk running into it. Well, I tried doing this with List. I replaced .length with .Count. Now I have "'Pop' and 'Unshift' is not a member of System.Collections.Generic.List[of TronTrailSelection]". What do I do about that?

avatar image Jessy · Feb 14, 2012 at 09:35 PM 0
Share

Study these: http://unity3d.com/support/documentation/ScriptReference/Array.html http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx You never should use the former, but for a case like this, you need to know how to translate to a better class.

avatar image by0log1c · Feb 14, 2012 at 10:27 PM 0
Share

This helped me a LOT when I started working with Unity) : http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use%3F

avatar image bdp · Feb 14, 2012 at 10:47 PM 0
Share

Thanks for all the suggetions. It's a lot for now but I'm looking over it all. I tried using sections.Add(section) for sections.Unshift(section) and sections.Clear() for sections.Pop(). It sort of works but the beginning of my trail doesn't disappear and stays visible. I'm getting a little lost, this is what happens when I try to modify something I didn't make. Any ideas?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by olivier etienne · Oct 07, 2013 at 01:15 AM

Ran into the same problem and found a solution ()

sections.Pop();

is to be replaced by the following 3 lines:

var sectionsarr = new Array (sections);

sectionsarr.Pop();

sections = sectionsarr.ToBuiltin(TronTrailSection);

and sections.Unshift(section);

is to be replaced by the following 3 lines:

sectionsarr = new Array (sections);

sectionsarr.Unshift(section);

sections = sectionsarr.ToBuiltin(TronTrailSection);

the rest of the code remain the same, and it works like charm!

Please see the full modified source below and let me if it works for you.

 #pragma strict
 /*
  Generates a trail that is always facing upwards using the scriptable mesh interface.
  vertex colors and uv's are generated similar to the builtin Trail Renderer.
  To use it
  1. create an empty game object
  2. attach this script and a MeshRenderer
  3. Then assign a particle material to the mesh renderer
 */
 var height = 2.0;
 var time = 2.0;
 var alwaysUp = false;
 var minDistance = 0.1;
 
 var startColor = Color.white;
 var endColor = Color (1, 1, 1, 0);
 
 class TronTrailSection
 {
     var point : Vector3;
     var upDir : Vector3;
     var time : float;
 }
 
 //private var sections = new Array();
 private var sections = new TronTrailSection[0];
 
 function LateUpdate () {
     var position = transform.position;
     var now = Time.time;
 
     // Remove old sections
     while (sections.length > 0 && now > sections[sections.length - 1].time + time) {
       var sectionsarr = new Array (sections);
       sectionsarr.Pop();
       sections = sectionsarr.ToBuiltin(TronTrailSection);
         //sections.Pop();
     }
 
     // Add a new trail section
     if (sections.length == 0 || (sections[0].point - position).sqrMagnitude > minDistance * minDistance)
     {
         var section = TronTrailSection ();
         section.point = position;
         if (alwaysUp)        
              section.upDir = Vector3.forward;
         else
             section.upDir = transform.TransformDirection(Vector3.forward);
         section.time = now;
         
         sectionsarr = new Array (sections);
         sectionsarr.Unshift(section);
         sections = sectionsarr.ToBuiltin(TronTrailSection);
         //sections.Unshift(section);
     }
     
     // Rebuild the mesh
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     mesh.Clear();
     
     // We need at least 2 sections to create the line
     if (sections.length < 2)
         return;
 
     var vertices = new Vector3[sections.length * 2];
     var colors = new Color[sections.length * 2];
     var uv = new Vector2[sections.length * 2];
     
     var previousSection : TronTrailSection = sections[0];
     var currentSection : TronTrailSection = sections[0];
 
     // Use matrix instead of transform.TransformPoint for performance reasons
     var localSpaceTransform = transform.worldToLocalMatrix;
 
     // Generate vertex, uv and colors
     for (var i=0;i<sections.length;i++)
     {
         previousSection = currentSection;
         currentSection = sections[i];
         // Calculate u for texture uv and color interpolation
         var u = 0.0;        
         if (i != 0)
             u = Mathf.Clamp01 ((Time.time - currentSection.time) / time);
         
         // Calculate upwards direction
         var upDir = currentSection.upDir;
         
         // Generate vertices
         vertices[i * 2 + 0] = localSpaceTransform.MultiplyPoint(currentSection.point);
         vertices[i * 2 + 1] = localSpaceTransform.MultiplyPoint(currentSection.point + upDir * height);
         
         uv[i * 2 + 0] = Vector2(u, 0);
         uv[i * 2 + 1] = Vector2(u, 1);
         
         // fade colors out over time
         var interpolatedColor = Color.Lerp(startColor, endColor, u);
         colors[i * 2 + 0] = interpolatedColor;
         colors[i * 2 + 1] = interpolatedColor;
     }
 
     // Generate triangles indices
     var triangles = new int[(sections.length - 1) * 2 * 3];
     for (i=0;i<triangles.length / 6;i++)
     {
         triangles[i * 6 + 0] = i * 2;
         triangles[i * 6 + 1] = i * 2 + 1;
         triangles[i * 6 + 2] = i * 2 + 2;
 
         triangles[i * 6 + 3] = i * 2 + 2;
         triangles[i * 6 + 4] = i * 2 + 1;
         triangles[i * 6 + 5] = i * 2 + 3;
     }
 
     // Assign to mesh    
     mesh.vertices = vertices;
     mesh.colors = colors;
     mesh.uv = uv;
     mesh.triangles = triangles;
 }
 
 @script RequireComponent (MeshFilter)
 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image olivier etienne · Oct 07, 2013 at 01:25 AM 0
Share

Forgot to mention that, at the beginning of the script:

private var sections = new Array();

is to be replace by

private var sections = new TronTrailSection[0];

avatar image decept · Mar 29, 2015 at 07:28 PM 0
Share

(Sorry for my english))Thanks! It works great, but trail moves with some angle.

if (alwaysUp)
section.upDir = Vector3.forward; else section.upDir = transform.TransformDirection(Vector3.forward);

So I paste "Vector3.up" ins$$anonymous$$d "Vector3.forward".

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Selection list from Array Unity - Random - GameObjects array 1 Answer

For all elements above a certain index 1 Answer

Create Array of Transforms and Detect Distance 3 Answers

Problem with adding 1 element of an array to a list 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges