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 /
This question was closed Jun 11, 2014 at 09:48 AM by fafase for the following reason:

Duplicate Question

avatar image
1
Question by Pwnographyz · Jun 11, 2014 at 06:00 AM · functioncallanotherfrom

Call a Function from another Script

So, the thing is. I want to Call a Function in another Script without referencing the Object it's attached to. Because the Script is added to multiple GameObjectes with different values I have to call a Function in It without using anything than the unused Script.

Hope someone can help me with that ;)

Your sincerely,

Pwnographyz

Comment
Add comment · Show 2
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 rutter · Jun 11, 2014 at 06:00 AM 0
Share

There are plenty of tutorials about this. You're going to want GetComponent, FindObjectsOfType, or some mix of both.

If you have a more specific question, please feel free to resubmit; otherwise, maybe try the forums or Google.

avatar image Zodiarc · Jun 11, 2014 at 08:58 AM 0
Share

As far as I know to call a function from another script you need some kind of reference if the script isn attached to the same object. If you want to reference the script only, try

 var script:ScriptName
 
 function Start(){
     script = GameObject.Find(Object the script is attached to).GetComponent("ScriptName") as ScriptName;
 }

1 Reply

  • Sort: 
avatar image
0

Answer by Kiwasi · Jun 11, 2014 at 09:15 AM

For time 752. Seriously, use Google or something. Not sure why a mod let this through.

List of ways to access another script

  • Use Find and GetComponent. Do this once and store the reference until you are done with it. Fastest method, should be used as default unless there is a good reason not to.

  • Use SendMessage. Best in cases where there might be more or less then one receiver on the target gameObject

  • Use static methods. Best for things like game managers and helper classes that don't change.

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

Follow this Question

Answers Answers and Comments

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

Related Questions

I'm having trouble referencing a function from one script inside another 1 Answer

Call function in another script? 1 Answer

Building a 3D Neural Network for Bot AI? 1 Answer

How to call a function from another script without referencing it? 1 Answer

Calling a Function from other script ( C# ) 1 Answer


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