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 27, 2013 at 01:35 PM · convertjs to c#

JS to C# conversion Problem

I was wanting to convert a js script over to C# and for the most part its done but I have one line giving me problems please help.

 using UnityEngine;
 using System.Collections;
 
 public class Lightning : MonoBehaviour {
 
 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 arc20.         
  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 to25.         
  i++;         
  lastPoint = fwd;//so we know where we are starting from for the next arc        
  }
  }


The line with the problem is

 public fwd = target.transform.position - lastPoint;//gives the direction to our target from the end of the last arc20.


If needed I can post the js version I was working from.

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 Graham-Dunnett ♦♦ · May 27, 2013 at 01:42 PM 2
Share

You're missing the type for fwd. BTW, why not post the errors that the compiler gives you, or take a screenshot or something like that. We're all helpful over here, but at least try and give us something to work with. I'd have retired by now if I charged $1 to answer a compile problem where the questioner hasn't given the line number or the compiler error. :-)

avatar image drawcode · May 27, 2013 at 01:54 PM 1
Share

Also next time hit this site to take a look at any line you have issues with: http://files.m2h.nl/js_to_c.php

1 Reply

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

Answer by Stormizin · May 27, 2013 at 01:39 PM

Try:

 Public Vector3 fwd;
 
 //code
 
 fwd = target.transform.position - lastPoint;//gives the direction to our target from the end of the last arc20.

Declare in the top of the script then remove the public from the fwd at Update function

Comment
Add comment · 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

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Could you help me convert this script to C#? 1 Answer

Please Help Convert js to c# 1 Answer

Convert .js to C# 2 Answers

Writing with c# and javascript simultaneoulsy 3 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