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 /
  • Help Room /
avatar image
0
Question by Mikeypi · Mar 05, 2016 at 09:49 AM · unity 5scripting problemscripting beginnerscripterror

Script problem: Trying to make the code of this script run at a set interval (GUI handle object)

This is what I am trying to do: I am fairly new so please be as descriptive as possible so that I may learn what I'm doing wrong and (hopefully) not repeat those mistakes.

On my game I have a handle which rotates right or left depending on mouse input clicks on the GUI. That aspect works fine, when the handle rotates it goes through colliders which in turn are supposed to be detected by this script when ran. That part (in theory) works fine, except that it is not running everytime the object moves to a new collision box. So In essence I am trying to find a way to make the thing run the script every so often (roughly 1 second). From looking around it seems the method using invoke repeat won't work with the way it's written so I had to use a coroutine. My knowledge with coroutines is very weak, in the compiler I show no errors but when I try to execute the script within the play preview of unity an error appears: "script error: OnTriggerStay2D The Message must have 0 or 1 parameters"

Because of this error it does not work so could someone please take the time and explain why I'm getting this error and how to make it go away. Or alternatively, a different means in which to repeat my script (the original context of the script is included in the bottom but disabled).

Note:The functions for the script are incomplete since it does little good to complete the conditions if it cannot even do part of it properly.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Throttle_Triggers : MonoBehaviour
 {
     private Collider2D other;
 
 
     // Use this for initialization
     void Start()
     {
         //Call your function
         StartCoroutine(OnTriggerStay2D(other));
     }
     IEnumerator OnTriggerStay2D(Collider2D other, float delayTime = 0f)
     {
         yield return new WaitForSeconds(delayTime);
         //You can then put your code below
         //......your code
         {
             if (GetComponent<Collider2D>() && gameObject.name == "Throttle_Stop")
                 gameObject.tag = "Throttle_Stop";
 
             else if (GetComponent<Collider2D>() && gameObject.name == "Throttle_1-3")
                 gameObject.tag = "Throttle_1-3";
             else
                 gameObject.tag = "Throttle1-3";
         }
     }
 
 
     // void OnTriggerStay2D(Collider2D other)
     //   {
     //      if (GetComponent<Collider2D>() && gameObject.name == "Throttle_Stop")
     //{
      //   gameObject.tag = "Throttle_Stop1";
     //}
     //else if (GetComponent<Collider2D>() && gameObject.name == "Throttle_13")
     //{
     //   gameObject.tag = "Throttle_13";
     //}
     //else
     //{
     //   gameObject.tag = "Throttle_23";
     //}

 
 }
 

Please also be aware there are 3 handles which function much the same, so bear that in mind in your response.

Thank you for your time in reading this and hopefully helping me solve it.

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
0

Answer by Mikeypi · Mar 05, 2016 at 12:32 PM

I was able to solve the problem by using a Switch instead of the If/Else system... Even still if someone could explain where I went wrong with that since I will likely need it again I would really appreciate it.

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

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

Related Questions

Script error 0 Answers

Highscore shows 0 upon restart, and the correct highscore appears again once the player scores 1 point 2 Answers

Adding a Highscore to game 1 Answer

error CS1061: Type `UnityEngine.Component' does not contain a definition for `position' and no extension method `position' of type `UnityEngine.Component' could be found. 1 Answer

Game Object 2 different movement pivots 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