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 ironblock · Dec 18, 2013 at 02:33 PM · positionconvertingjs-c#

js to c# converting trouble

I'm converting a js script to a c# script but i am stuck on this part. I'm trying to draw a line between objects

     for (int i=0; i<path.Count; i++) {
         new Vector3 pos = path[i];
         if (i>0) {
             var prev=path[i-1].position;
             new Gizmos.DrawLine(prev,pos);
             Gizmos.DrawWireSphere(pos,0.6f);
         }
     }
 
 
 edit : 
 prev=path[i-1].position is the big problem here i just cant get it to work.

this is the full script

 var path:Array;
 var rayColor:Color=Color.white;
 
 function OnDrawGizmos(){
 Gizmos.color=rayColor;
 var path_objs:Array;
  path_objs=transform.GetComponentsInChildren(Transform);
  path=new Array();
  for(var path_obj:Transform in path_objs)//dit kan een forEach zijn 
  {
   if(path_obj!=transform)
   {
    path[path.length]=path_obj;
   }
  }
  for(var i:int=0;i<path.length;i++)
  {
   var pos:Vector3=path[i].position;
   if(i>0)
   {
    var prev=path[i-1].position;
    Gizmos.DrawLine(prev,pos);
    Gizmos.DrawWireSphere(pos,0.6);
   }
  }
 }

edit : the answer was Transform pos = (Transform)path[i];

Comment
Add comment · Show 2
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 fafase · Dec 18, 2013 at 02:35 PM 1
Share

It seems you'd better stay in Js since you do not seem to know C#.

  new Vector3 pos = path[i]; -> Vector3 pos = path[i];
  new Gizmos.DrawLine(prev,pos); -> Gizmos.DrawLine(prev,pos);
avatar image ironblock · Dec 19, 2013 at 09:52 AM 1
Share

that's great ... except it does not work because you cant do .position this is the full script and yes it does work in js.

if you're the c# developer you say you are you can fix it can't you ? thanks in advance

 var path:Array;
 var rayColor:Color=Color.white;
 
 function OnDrawGizmos(){
 Gizmos.color=rayColor;
 var path_objs:Array;
  path_objs=transform.GetComponentsInChildren(Transform);
  path=new Array();
  for(var path_obj:Transform in path_objs)
  {
   if(path_obj!=transform)
   {
    path[path.length]=path_obj;
   }
  }
  for(var i:int=0;i<path.length;i++)
  {
   var pos:Vector3=path[i].position;
   if(i>0)
   {
    var prev=path[i-1].position;
    Gizmos.DrawLine(prev,pos);
    Gizmos.DrawWireSphere(pos,0.6);
   }
  }
 }

 

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by stevethorne · Dec 18, 2013 at 03:04 PM

Update: this is using the full script you posted.

 List<Transform> path;
 Color rayColor = Color.white;
 
 void OnDrawGizmos()
 {
     Gizmos.color = rayColor;
     Transform[] path_objs;
     path_objs = transform.GetComponentsInChildren<Transform>();
     path = new List<Transform>();
     foreach (Transform path_obj in path_objs)//dit kan een forEach zijn 
     {
         if(path_obj != transform)
         {
             path.Add( path_obj );
         }
     }
     for( int i = 0; i < path.Count; i++ )
     {
         Vector3 pos= path[i].position;
         if( i > 0 )
         {
             Vector3 prev=path[i-1].position;
             Gizmos.DrawLine( prev, pos );
             Gizmos.DrawWireSphere( pos, 0.6f );
         }
     }
 }

I tried as best as I could to interpret what you wanted from your js script and converted it to c#. I have no compile errors when I put this in my project.

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 stevethorne · Dec 19, 2013 at 02:11 PM 0
Share

I've also tested this code and it's working great in editor.

avatar image stevethorne · Dec 20, 2013 at 04:55 PM 0
Share

Did this give you what you need?

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

do you know what version of unity was released in the end of 2012? 0 Answers

Camera rotation around player while following. 6 Answers

Freeze rigidbody position without affecting rotation - please help! 1 Answer

making position checker - is area empty or not (with trigger)? 2 Answers

How to change animation in the code? 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