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 Tiki · Sep 07, 2013 at 04:17 AM · c#javascriptvector3vector2

Transfer values from C# to Javascript

What would be the easiest way to move values from, for example, a Vector4 array in C#, to the same in Javascript?

Comment
Add comment · Show 7
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 ArkaneX · Sep 07, 2013 at 07:30 AM 0
Share

The easiest way would be to search this site a bit. There is A LOT of information related to this topic.

avatar image Tiki · Sep 07, 2013 at 10:21 AM 0
Share

I haven't found much, is there some keywords I should be using? The best I've found is not on this site, it's the "[% %]" method, which I already know. I'm wondering what, if any, alternative methods Unity allows. I don't $$anonymous$$d searching, I'm just not doing it well right now, help me out, please.

avatar image ArkaneX · Sep 07, 2013 at 12:03 PM 0
Share

Now you have triggered my curiosity - what you mean by "[% %]" method? Did you mean

 <%= %>

syntax? If yes, then it is used in ASP.NET and it's completely unrelated to Unity. If, on the other hand, you meant something else, could you please add a link to an example?

As to your issue - I assume you have some object with both C# and JavaScript attached and you want to access properties/fields on one in second. If yes, then it's not possible, unless C# script is in for example Plugins folder. For details, check the answer to this question.

If your problem is different, then please post additional details.

avatar image Tiki · Sep 07, 2013 at 06:50 PM 0
Share

Yes that's the method I was referring to, I'm aware of it's limitations that's why I'm looking for a Unity method. I used brackets because I hadn't noticed the blockquote button and it was reading it as html in normal text, removing it from the page.

What I'm trying to do is generate noise values through libnoise-net, which is built on c#, then use those values in a javascript function. For instance, I would fill a Vector4 Array of X size in C#, then utilize the values in javascript to generate terrain.

I'm fairly sure I could simply write the values to an external source and then fill a Uscript vector4 with that source, right? I'm just wondering if Unity allows a simpler, faster method.

avatar image Tiki · Sep 07, 2013 at 07:21 PM 0
Share

This was suggested by another user:

 using UnityEngine;
 using System.Collections;
  
 public class someCS: $$anonymous$$onoBehaviour {
     public Vector4[] someArray;
  
     void Start () {
         someArray = new Vector4[1];
         someArray[0] = new Vector4( 0, 1, 2, 3 );
     }
 }

//C# ^ Javascript v

 function Start () {
     print(GetComponent.<someCS>().someArray[0]);
 }


Can I use this method to somehow print the values into a javascript function rather than the display? For instance a uscript Vector4?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ArkaneX · Sep 07, 2013 at 10:33 PM

After some comments, I have a full view of your problem. Or at least I hope so :)

You have a library written in C#, but for your Unity project you're using JavaScript. In one of your comments you wrote 'uscript Vector4', but there's no difference between Vector4 in UnityScript/JavaScript and Vector4 used in C#. Both are .NET types. It means, if some method in your library returns Vector4 array, you can call it from UnityScript directly, after you put this library in the Assets folder.

For example, assuming that the library contains a class NoiseGenerator with a method

 public static Vector4[] Generate()

you can simply use

 var someArray : Vector4[] = NoiseGenerator.Generate();
Comment
Add comment · Show 5 · 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 Tiki · Sep 08, 2013 at 04:48 AM 0
Share

I was wondering if they worked globally like that, thank you very much ArkaneX, I'll give this a try and let you know how it works out.

avatar image fafase · Sep 08, 2013 at 06:28 AM 0
Share

@Arkanex, putting it in the Asset folder will not solve the issue.

avatar image ArkaneX · Sep 08, 2013 at 09:28 AM 0
Share

@fafase - why not? We're not talking about script but about third party assembly. It is already compiled.

avatar image fafase · Sep 08, 2013 at 09:57 AM 0
Share

Oh yes, I skipped the lib part he described. $$anonymous$$y bad.

avatar image vexe · Oct 11, 2013 at 05:52 AM 0
Share

@Tiki

I'll give this a try and let you know how it works out.

Are you still giving it a try?

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

How to get the World position of a connectedAnchor? (2d) 1 Answer

Distribute terrain in zones 3 Answers

Natural camera sway 1 Answer

Fixed error but error still shows in the console 2 Answers

Get a position relative to a gameobject 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