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 davidflynn2 · May 16, 2013 at 02:05 PM · c#

Converting to C#

I have been trying to convert this over to C# for a few days now with no luck could some one please help me.

 var target : GameObject;
 var LR : LineRenderer;
 var arcLength = 2.0;
 var arcVariation = 2.0;
 var inaccuracy = 1.0;
 
 function Update() {
     var lastPoint = transform.position;
     var i = 1;
     LR.SetPosition(0, transform.position);//make the origin of the LR the same as the transform
     while (Vector3.Distance(target.transform.position, lastPoint) >.5) {//was the last arc not touching the target? 
             LR.SetVertexCount(i + 1);//then we need a new vertex in our line renderer
             var fwd = target.transform.position - lastPoint;//gives the direction to our target from the end of the last arc
             fwd.Normalize();//makes the direction to scale
             fwd = Randomize(fwd, inaccuracy);//we don't want a straight line to the target though
             fwd *= Random.Range(arcLength * arcVariation, arcLength);//nature is never too uniform
             fwd += lastPoint;//point + distance * direction = new point. this is where our new arc ends
             LR.SetPosition(i, fwd);//this tells the line renderer where to draw to
             i++;
             lastPoint = fwd;//so we know where we are starting from for the next arc
          }
 }
 
 function Randomize (v3 : Vector3, inaccuracy2 : float) { 
    v3 += Vector3(Random.Range(-1.0, 1.0), Random.Range(-1.0, 1.0), Random.Range(-1.0, 1.0)) * inaccuracy2; 
    v3.Normalize(); 
    return v3; 
 }
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 robertbu · May 16, 2013 at 02:18 PM 2
Share

Why don't you edit your question to post your attempt along with the code above. Someone on the list can then help you with any remaining issues.

http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by programmrzinc · May 16, 2013 at 02:15 PM

Here I am not sure what you need to import, or declaring fwd

 imports System.Collection;
 
 imports Unity.Engine;
 
 public GameObject target;
 public LineRenderer LR;
 public double arcLength = 2.0;
 public double arcVariation = 2.0;
 public double inaccuracy = 1.0;
 
 void Update(){
 
 Vector3 lastPoint = transform.position;
 int i = 1;
 
 LR.SetPosition(0, transform.position);//make the origin of the LR the same as the transform
     while (Vector3.Distance(target.transform.position, lastPoint) >.5) {//was the last arc not touching the target? 
             LR.SetVertexCount(i + 1);//then we need a new vertex in our line renderer
             public fwd = target.transform.position - lastPoint;//gives the direction to our target from the end of the last arc
             fwd.Normalize();//makes the direction to scale
             fwd = Randomize(fwd, inaccuracy);//we don't want a straight line to the target though
             fwd *= Random.Range(arcLength * arcVariation, arcLength);//nature is never too uniform
             fwd += lastPoint;//point + distance * direction = new point. this is where our new arc ends
             LR.SetPosition(i, fwd);//this tells the line renderer where to draw to
             i++;
             lastPoint = fwd;//so we know where we are starting from for the next arc
          }
 
 
 
 }
Comment
Add comment · Show 4 · 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 davidflynn2 · May 16, 2013 at 02:21 PM 0
Share

It dont like this line "public fwd = target.transform.position - lastPoint;".

avatar image Chronos-L · May 16, 2013 at 02:40 PM 1
Share

This is not yet a complete c# translation. The following are some additions to @programmrzinc's answer

 import UnityEngine;
 import System.Collections;
 
 public class ClassName : $$anonymous$$onoBehaviour {
    
    //variables
    public GameObject target;
    ...
 
    void Update() {
       ...
    } 
 
    private Vector3 Randomize( ... ) {
       ...
    }
 }


Please note that the ClassName should have the same name as your script, eg: XYZ.cs will have public class XYZ : $$anonymous$$onoBehaviour. This is the default when you create a .cs from Unity.

avatar image TheDarkVoid · May 16, 2013 at 08:24 PM 0
Share

accept the answer if it helped. click the check

avatar image davidflynn2 · May 17, 2013 at 07:39 PM 0
Share

It dont like this line "public fwd = target.transform.position - lastPoint;".

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

17 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

Related Questions

Multiple Cars not working 1 Answer

Lightning Script Js To C# Conversion errors 2 Answers

Render only on specific times of year 1 Answer

Distribute terrain in zones 3 Answers

this is part of my health script it gives me a error unknown identifier GameScore pls help thxxx 0 Answers


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