Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 JacobHunterTX · Jun 28, 2016 at 04:36 PM · errorgetcomponentgetcomponentinchildren

Why can't monodevelop find this public method in my component?

I'm scripting an 'offlineGUI' to manage some GUI in a little 2D game, but I'm having trouble accessing a certain public method in my game player component:

 GetComponentInChildren<offlinePlayer> ().getBool("goAhead")

When I try to build, the above line gives the following error:

 Type 'offlinePlayer' does not contain definition for 'getBool' and no extension method 'getBool' of type 'offlinePlayer' could be found. Are you missing an assembly reference?

The 'getBool' method in my 'offlinePlayer' class is public. I can access other public methods from that class in my 'offlineGUI' by using the GetComponentInChildren() method without issue. Thanks for any answers!

Edit: Here's the offlinePlayer class: using UnityEngine; using System.Collections; using UnityEditor.SceneManagement;

 public class offlinePlayer : MonoBehaviour {
 //switches
 private bool running; //is the game running?
 private bool goAhead = true; //used to bring the game from not running to running
 private bool timeUp; //is time less than 0?
 private bool newGame; //is the game just beginning?
 private bool gameOver; //turned on once a team gets the max points

 //time variables
 public float roundTime; //time per round
 public float timer;

 //team scores
 private int redScore;
 private int blueScore;

 //point button measurements
 public float buttonWidthRatio = 0.3f;
 public float buttonHeightRatio = 0.2f;
 public float buttonXRatio = 0.1f;
 public float buttonYRatio = 0.1f;

 //game over button measurements
 public float gameOverButtonWidthRatio = 0.5f;
 public float gameOverButtonHeightRatio = 0.5f;
 public float gameOverButtonXRatio = 0.1f;
 public float gameOverButtonYRatio = 0.1f;

 public void signalStart(){
     if (newGame) {
         redScore = 0;
         blueScore = 0;
         newGame = false;
     }
     timer = roundTime;
     if (!running && goAhead) {
         GetComponentInChildren<gametext> ().startSignal ();
         running = true;
         timeUp = false;
         goAhead = false;
     }
 
 }

 public bool getBool (string name){
     switch (name){
     case "goAhead":
         return goAhead;
     case "timeUp":
         return timeUp;
     case "newGame":
         return newGame;
     case "gameOver":
         return gameOver;
     }
 }

 public bool checkStatus () {
     return running;
 }
     

 public void toggleStatus () {
     if (running)
         running = false;
     else 
         running = true;
     
 }

 void Update() {

     if (running) {
         timer -= Time.deltaTime;
         if (timer < 0.0) {
             running = false;
             timeUp = true;
             GetComponentInChildren<countdown> ().timeUp ();
         
         }
     }
 
 }

 void addPoints(int team, int points){
     if (team == 1) {
         if (points == 1)
             redScore++;
         else
             redScore += 2;
     } else {
         if (points == 1)
             blueScore++;
         else
             blueScore += 2;
     }

     //logic for if one team wins
     if(redScore>5||blueScore>5){
         gameOver = true;
     }


 }
Comment
Add comment · Show 3
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 Hellium · Jun 27, 2016 at 08:58 PM 0
Share

Please, provide the offline class

avatar image JacobHunterTX Hellium · Jun 28, 2016 at 03:31 PM 0
Share

I have provided it now.

avatar image StormMuller · Jun 28, 2016 at 09:43 PM 0
Share

Why are you you creating a new method to get bools? why not just use properties or enums?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessespike · Jun 28, 2016 at 10:00 PM

The method cannot be found, because scripts with errors will not compile.

Specifically the issue is that getBool expects to return a bool, but there is a case where nothing is returned.

 error CS0161: `offlinePlayer.getBool(string)': not all code paths return a value


  public bool getBool (string name){
      switch (name){
      case "goAhead":
          return goAhead;
      case "timeUp":
          return timeUp;
      case "newGame":
          return newGame;
      case "gameOver":
          return gameOver;
      }
      // fallback if no matching case exists
      Debug.Log("Unable to get bool: " + name);
      return false; 
  }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Error CS0426 expression denotes a type' where a variable' value' or method group' was expected Rigidbody.velocity problem? 1 Answer

Scrolling List List Item Manager 1 Answer

why i am getting this errorr.... 1 Answer

Problem Destroying Component 0 Answers

Using GetComponent without knowing the script name? 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