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 srancsik · Oct 22, 2013 at 10:48 AM · gameobjectvariableaccessanother

SOLVED - Accessing a C# script value from another GameObject's JavaScript

I read a lot of forum threads and answers about accessing other GameObject's scripts. In case of C# I am totally fine, but I need to write a reference into a JavaScript to access a C# script. As long as they are on the same GameObject, everything is fine. But how do you modify the following line (not being attached to "Rmenu" object) to access "Rmenu" object, "Page" script "PageNumber" public variable?

var x = GameObject.Find("Rmenu").GetComponent(Page).PageNumber;

I'm keep getting the error message: BCE0018: The name 'Page' does not denote a valid type ('not found').

As always any answer and hints are welcome and thanked in advance.

Comment
Add comment · Show 5
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 · Oct 22, 2013 at 11:16 AM 1
Share

Please read this: http://answers.unity3d.com/questions/540026/how-to-move-data-between-js-cs-script-.html

Accepted answer will give you a quick info, while reading links from my answer will help you understand why it works this way.

avatar image ArkaneX · Oct 22, 2013 at 11:19 AM 3
Share

Please accept/upvote helpful answers and comments to your previous questions (you can even mark your own answer if it is valid). To learn why it is important, I suggest reading FAQ and watching tutorial video (links on the right).

avatar image ArkaneX · Oct 22, 2013 at 12:26 PM 1
Share

You'll have to deal with this kind of errors whether you program in C# or JS, as long as you need to access scripts written in a different language. The best option is to just stick to one language.

And I disagree that C# is less flexible :)

avatar image srancsik · Oct 22, 2013 at 12:32 PM 0
Share

The problem is that if you buy something from the asset store, it depends on the programmer's favor our whether he/she uses Javascript or C#.

I am a noob in program$$anonymous$$g, therefore I am struggling with the access of all public variables no matter if C# or Javascript.

The best would be something like Visual Basic, making a variable public would be seen all over the place. :)

avatar image ArkaneX · Oct 22, 2013 at 12:49 PM 0
Share

I agree that asset store products use different languages, but majority of their scripts land in Standard Assets folder, so it is possible to reference them in any language.

2 Replies

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

Answer by srancsik · Oct 22, 2013 at 12:04 PM

Dear ArkaneX,

I can not believe I fell into the same trap as previously. Due to a similar un-accessibility I started putting my scripts into "Standard Assets" folder. As you suggested I moved my Javascript out of this folder and immediately everything was working. Reading the referenced links you sent me, I understand that in C# this is not a problem. I highly consider sticking to C# only, in spite it seems less flexible when programming. But anyway:

I AM VERY GREATFUL FOR YOUR HELP, THANK YOU!!!

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

Answer by btb200 · Oct 22, 2013 at 12:28 PM

You have to write public method in your JS Class:

 function SetX(xVal){

 }


and in your C# class use:

 GameObject.Find("GameObjectName").GetComponent ("JSClassName").SendMessage ("SetX", xValue);


It will send value of X from C# class to JS class.

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

Getting a variable from another object 1 Answer

How to access gameObject variable script 2 Answers

Can't access variable from another script. 1 Answer

Cannot access a variable in another Script. 2 Answers

Access guiText from other object. 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