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 R1pnd1p · May 24, 2015 at 12:26 PM · c#errorunity5monobehaviourfunctions

Referencing NON-monobehavior scripts - getting an error :/

ok so heres the issue, my questing is not in regards to the details but to the generality of it all.

2 scripts: 1.)the first one is a NON monobehavior script, instead its set as [System.Serializable]. 2.)the second one IS a monobehavior script.

the 1st script is called Enemy, and its variables can be referenced in "void ObtainEnemyID (Enemy enemy)" just fine.

but, the debug wont allow the script to pass because of the missing information that it requires at "ObtainEnemyID();".

im pretty convinced that this has a simple solution, just not sure exactly what i need to place within the parentheses.

i dont want to bug you guys with a million lines of code, so i broke the question down to (what i believe) is the root of the problem.

thanks so much for your help and brain power.

-r1pnd1p :)

if (CONDITIONS) {

   ObtainEnemyID();  //error: non overload for method 'ObtainEnemyID' takes '0' arguments.
  }
  
    void ObtainEnemyID (Enemy enemy)
  {
   enemy.enemyID = enemyai.id;
  }
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 cjdev · May 25, 2015 at 05:57 AM

As it currently stands your function ObtainEnemyID requires a parameter of type Enemy, which is why you're getting the error. You can either create a new Enemy object and pass it into the function when you call it or you can make it so that the function's parameter is optional by setting it equal to null like this:

 public void ObtainEnemyID (Enemy enemy = null)
 {
    // function contents
 }

What this will do is let you call the function with no parameter, setting the default to null (or whatever you want it to be). Another option you have is to 'overload' the function with another function of the same name and different parameters:

 public void ObtainEnemyID()
 {
    // function contents
 }
 
 public void ObtainEnemyID(Enemy enemy)
 {
    // function contents
 }

With this method you can declare a specific function for a given parameter type which enables you to do something unique in that case, but you'll have to write another implementation for it. Hopefully this answers your question, if I misread it let me know.

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 R1pnd1p · May 25, 2015 at 08:42 PM 0
Share

thanks alot man. perfect, not only did you answer it well, you explained it well.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

No Monobehaviour script in the file error Unity 2019.2 2 Answers

Multiple Cars not working 1 Answer

No Monobehaviour scripts in files 1 Answer

Distribute terrain in zones 3 Answers

Problem with attaching scripts to objects 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