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 benfattino · Jun 02, 2012 at 01:56 PM · stringsplit

String split script

I'm using this script to draw wireframe. Script read from string file, split coordinate and make vector3 array. In desktop mode all ok, but now in iOS give me error:

Assets/Script/Wireframe.js(33,23): BCE0050: Operator '-' cannot be used with an expression of type 'Object'.

 import System.IO;
 var Filename : String;
 
 var lineMaterial : Material;
 var lineColor : Color;
 var lineAlpha : float;
 var lineThickness = 1.0;
 var line3D = false;
 
 private var line : VectorLine;
 private var LinesArray : Vector3[];
 private var PointsList : Array;
 private var Lines : Array;
 private var i : int;
 
 function Start () {
     var sr = new StreamReader(Application.dataPath + "/" + Filename);
     var fileContents = sr.ReadToEnd();
     sr.Close();
     var Points = fileContents.Split(","[0]);
   
     //PointsList = new Array();
     for (i = 0; i < Points.length; i++){ 
     PointsList.Add(float.Parse(Points[i]));    
   }
     //Lines = new Array();
     for (i = 0; i < PointsList.length / 3; i++){ 
     Lines.Add(Vector3(-PointsList[i*3],PointsList[i*3+2],-PointsList[i*3+1]));
 } 
     LinesArray = Lines.ToBuiltin(Vector3); 
     line = new VectorLine("Line", LinesArray, lineColor, lineMaterial, lineThickness); 
     VectorManager.useDraw3D = line3D;
     line.joins = Joins.Weld;
     VectorManager.ObjectSetup (gameObject, line, Visibility.Dynamic, Brightness.None);   
 }
 
 function LateUpdate (){
     line.vectorObject.renderer.material.color.a = lineAlpha;
 }

Somebody help me to correct script?

Comment
Add comment · Show 1
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 kolban · Jun 02, 2012 at 02:22 PM 0
Share

Can you indicate in your script which line is line "33"?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wolfram · Jun 02, 2012 at 02:25 PM

The "Array" type is an untyped collection of arbitrary objects, so although you put floats in, the compiler doesn't know that when you're accessing the elements again.

I'm not a Master of UnityScript, since I always use C#, so I don't know what the best alternative is. But your problem should be solved by replacing every "PointsList[..." in your line starting with "Lines.Add" with "(float)PointsList[...", or maybe "float(PointsList[...])". In C# you could do "PointsList[...] as float", but I don't know if that's available in UnityScript.

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 benfattino · Jun 02, 2012 at 10:12 PM 0
Share

Lines.Add(Vector3(-PointsList[i*3],PointsList[i*3+2],-PointsList[i*3+1]));

avatar image Eric5h5 · Jun 02, 2012 at 10:36 PM 0
Share

The best alternative is a generic List; the JS Array class should not be used even in JS.

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

6 People are following this question.

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

Related Questions

Extract number from string? 3 Answers

how can i split a word to individual letters..?? 2 Answers

StringSplitOptions.RemoveEmptyEntries - Unknown identifier 2 Answers

issues splitting strings 1 Answer

StringTable manager singleton creation 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