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
1
Question by Goody! · Dec 08, 2009 at 02:11 AM · bce0019

Accessing functions in other scripts.

In Javascript, I have tried the method listed here...

http://answers.unity3d.com/questions/32/how-do-i-call-a-function-in-another-gameobjects-script

...but following it got the error: Assets/HazardStatic.js(18,23): BCE0019: 'Test' is not a member of 'UnityEngine.GameObject'.

The scenario is thus: I have two scripts named Testing and HazardStatic both assigned to the same game object named HazFlowerCol.

In the Testing script are a static var named "test" and a static function named "Test".

I can access and change the var "test" but cannot trigger the function "Test".

I will vote answered to the answer that leads to my HazardStatic script being able to call the Test function in Testing. Please be explicit in your JavaScript answer as I have already been through everything I could on this page without success:

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

to no avail.

Thanks!

--Goody!

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 Goody! · Dec 08, 2009 at 02:14 AM 0
Share

And I may even upvote you if you can do it without using the words "simple" or "simply". :)

1 Reply

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

Answer by Jaap Kreijkamp · Dec 08, 2009 at 02:22 AM

EDIT: added example with static and nonstatic functions/vars

If you use the method as in the docs you mentioned, you have to connect the script ScriptB to the other property of ScriptA. You do this by drag/dropping the gameobject self onto the property other of ScriptA in the inspector. For static functions and vars you refer them using the scriptname, e.g. ScriptB.staticVar or ScriptB.StaticFun().

Examples:

ScriptA

var other : ScriptB;

function Update () { other.testValue = 1; other.Test(); other.staticTestValue = 2; ScriptB.StaticTest(); }

ScriptB

var testValue : int = 0; static var staticTestValue : int = 0;

static function StaticTest() { Debug.Log("Static Test: " + staticTestValue); }

function Test() { Debug.Log("Test: " + testValue); }

Comment
Add comment · Show 3 · 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 Goody! · Dec 08, 2009 at 03:33 AM 0
Share

Wonderful! Thank you so much for the script example! It makes testing it out and fiddling with it $$anonymous$$UCH easier! I'd tried the method of selecting an object but not drag/dropping and with your concise directions it worked great.

avatar image Goody! · Dec 08, 2009 at 03:36 AM 0
Share

Dang! I cannot upvote yet (I tried but it says I need 15 Unity$$anonymous$$agicPoints to do so) but I would if I could. :)

avatar image Goody! · Dec 08, 2009 at 10:16 PM 0
Share

Somehow I now have 33 $$anonymous$$agicHappyPoints! Upvoted!

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Pragma Strict Question/Problem 1 Answer

Missile script is suddenly giving errors 1 Answer

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 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