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 zachypin · Jun 27, 2011 at 05:55 PM · callcommunicationoop

Call CS from JS in one gameobject

I've looked through a bunch of the questions on here involving this but they don't answer in a way that seems logical for my use. So here it goes: (I've added in the script because I find it useful answering questions with it, though I don't think it may be necessary to answer this question)

Thanks for the look!

First the Hierarchy.
-Animations
o-Communicator
oo-Interaction

On the "Interaction" level I have a child object that I click/interact with and it triggers CS code called "UpButton". This code triggers a boolean value to be made true in a function "WasUpPressed":

     bool upPressed = false;
             
     void OnMouseDown()
     {
         upPressed = true;
     }
             
     bool WasUpPressed()
     {
         return upPressed;
     }

Now on the "Communicator" level I have a JS. This tells an animation to play on the "Animation" level if it "hears" that "WasUpPressed" returns true :

     var upbutton = false;

     function Update () 
     {    
 
          upbutton = GetComponent(UpButton);
          upbutton.WasUpPressed();
 
          if(upbutton)
          {
              transform.parent.gameObject.animation.Play("m-1");
          }
      }



To me it seems as if this would work, however, I can't even see if it does because it won't compile in the Project for me to be able to even attach it to my gameObject. The error I get is "Unknown Identifier: 'UpButton'" which will obviously be the case if the script isn't attached to the gameObject. So how do I fix this??

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

1 Reply

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

Answer by GuyTidhar · Jun 27, 2011 at 06:11 PM

The CS script is not compiled before the JS.

If you place the JS in a folder other then "Plugins" folder, and make sure the CS is under the "Plugins" folder, the code in the CS will be known in the JS.

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 zachypin · Jun 27, 2011 at 06:35 PM 0
Share

That seems like such a work around though. I have all my folders setup so that I know where all my code is and it's nice and orderly. You're saying for a JS to talk to a CS I have to make Unity think that my CS is a plugin? No offense to you but that just seems absurd if that's the only method Unity deals with this.

avatar image dibonaj · Jun 27, 2011 at 06:49 PM 0
Share

http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html

Unity compiles things in a certain order. It is not a work around, it is just the way it works.

avatar image zachypin · Jun 27, 2011 at 07:02 PM 0
Share

It's just weird I can't just attach a flag or something that tells Unity to look at this script before this one. Pretty much a user guided dependency hierarchy.

But anyways!

I put the scripts inside of Plugins as you guided and one error went away. Not sure if it's directly related so I created a new question.

http://answers.unity3d.com/questions/136247/component-call-not-recognizing-boolean-syntax-erro.html Thanks for the info guys!

avatar image dibonaj · Jun 27, 2011 at 07:18 PM 0
Share

You're welcome. That was one of the biggest problems I had when I got into Unity.

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

An OS design issue: File types associated with their appropriate programs 1 Answer

Type 'Force' does not contain a definition for 'Operation' 1 Answer

Bluetooth Communication 2 Answers

Communicating variables between Scripts for Attacks 1 Answer

Switches that represent object state 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