Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 JungDuckSoo · Sep 13, 2011 at 05:30 AM ·

communication between scripts

I can't know the way how to communicate between the scripts. I try to change variable A on JavaScript A at JavaScript B(CScript B). But I don't know how to change it. How can I do it? Also I want ask one more question. Can I communicate between C Script and Java Script? Then How?

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 robert_mathew · Sep 13, 2011 at 05:58 AM 0
Share

it is difficult to communicate between c# and java script you can only delay the execution but you can easily communicate between c# and c#

java script and java crip

2 Replies

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

Answer by GuyTidhar · Sep 13, 2011 at 07:03 AM

There are several things to take in account in order to understand the answer to your question.

  1. A script is a set of rules you define.

  2. In order for these rules to exist in the computer's memory when you need them you can either make make an instance of them (by declaring a variable of the type of script you defined) or declare some of the definitions within this set of scripts as static (functions or variables within the script you wrote). When you declare something as static, it means it will have one instance in memory and each time you call that static variable or function you use that exact instance (you can not make an instance of a static object).

In order to access a variable in script A from script B, you would usually do the following: Lets assume both scripts are javascript:

1) Make a 2 new javascript file: ScriptA.js ScriptB.js

2) In ScriptA, lets say you want an integer defined. You would write within ScriptA:

var myInteger : int = 0;

3) In ScriptB, lets say you wish to use this integer:

 var my1ScriptAinstance : ScriptA = null;
 var my2ScriptAinstance : ScriptA = null;
 
 function Start()
 {
    // Create 2 instances of ScriptA in memory
    my1ScriptAinstance = new ScriptA();
    my2ScriptAinstance = new ScriptA();
 }
 
 function Update()
 {
     // Each time Update is called, print and then increase myInteger in my1ScriptAinstance by 1
     Debug.Log("My 1st integer = " + my1ScriptAinstance.myInteger++);

     // Each time Update is called, print and then decrease myInteger in my2ScriptAinstance by 1
     Debug.Log("My 2nd integer = " + my2ScriptAinstance.myInteger--);
 }

You can also have one or both of these scripts defined as C# (though you need to change the code for C#). In order for that to work you need to consider when each of these scripts get compiled. It depends on where you actually place the C# script and the JS script - the script X you which to access from script Y, must be compiled before script Y, or else script Y won't understand what you are referring to (compilation is the process of creating the actual machine code from the human language set of rules you defined in the JS or C# script). In order to understand more about compilation order in Unity, check this out: http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html

NOTE: you also have the option to learn to use the SendMessage (http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=SendMessage). I highly recommend against it, as it involves in making your code work much slower, unless you use it in very specific places.

Comment
Add comment · Show 1 · 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 JungDuckSoo · Sep 13, 2011 at 08:43 AM 0
Share

Thank you very much. Best

avatar image
0

Answer by robert_mathew · Sep 13, 2011 at 07:04 AM

http://forum.unity3d.com/threads/21098-Calling-c-from-JS-and-vice-versus

http://forum.unity3d.com/threads/19800-How-do-you-communicate-between-scripts

http://answers.unity3d.com/questions/140335/communicate-between-two-bools-c.html

http://unity3d.qatohost.com/questions/18281/trying-to-set-a-javascript-variable-from-c-sharp.html

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Invalid rank specifier error 0 Answers

How to make the trigger work only once. (SOUND) 1 Answer

Add a Rigidbody to prefab using script 3 Answers

Best way to create a train. 0 Answers

Creating A wall Jump 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