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 $$anonymous$$ · Oct 05, 2014 at 11:58 PM · colliderontriggerenterienumeratorother

Calling a coroutine when the IENumerator has a passing argument?

Trying to call a coroutine, but I get an error: " Unexpected symbol "other" " in the start method

     void Start()
     {
         StartCoroutine(OnTriggerEnter(Collider other));
     }


Coroutine:

      IEnumerator OnTriggerEnter(Collider other)
     {
         if (other.tag == "Pickup") 
         {
             Vector3 spawnPlusPoint = new Vector3(0,0,0);
             plusPoint.text = "+3";
             Instantiate(plusPoint, spawnPlusPoint, Quaternion.identity);
 
             yield return new WaitForSeconds(1.5f);
             plusPoint.text = "";
         }
     }





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

2 Replies

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

Answer by Bunny83 · Oct 06, 2014 at 12:16 AM

You have several things wrong here. First of all when calling a method (no matter if it's a "normal" method or a generator method, an IEnumerator) you have to pass the parameters the method requires in it's declaration. Inside your Start method you don't pass a variable, it looks like you just copied the parameter declaration which makes no sense at all.

Your second problem is OnTriggerEnter is a callback that is called by Unity automatically. Usually it makes no sense to call it manually. Even if you want to call it manually you should make yourself clear what collider you want to pass to the function. Are you sure you know what you actually want to do? And if so could you please explain that in your question?

If you want to start the coroutine manually you have to call it like this:

 StartCoroutine(OnTriggerEnter(someColliderReference));

where "someColliderReference" is the collider you want to pass.

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 $$anonymous$$ · Oct 06, 2014 at 06:22 PM 0
Share

Wow, thanks man. Thought you always had to start a coroutine for it to work, I just took out that line from the Start method and it works fine. Would rep but I can't because I'm new.

Thanks

avatar image
-1

Answer by OctoMan · Oct 06, 2014 at 12:23 AM

Starting the coroutine with a value(string,int,bool, float and so on), is what you have to do normally.

example: StartCoroutine(OnTriggerEnter(1.0f));

and in IEnumerator OnTriggerEnter(float value) to make use of the value inside of the IEnumerator.

like: yield return new waitforseconds(value);

So you might want to store the collider somehow in a variable. Not sure if thats possible.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

issue with making a moving object trap c# (SOLVED) 2 Answers

BoxCollider Overlap OnTriggerEnter Problem 1 Answer

Trigger Spawning? 1 Answer

How to make player go through object but can't go back 3 Answers

Having trouble making Float up and fade out text on Collide. 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