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 BeCzech · Dec 10, 2015 at 11:37 PM · boolif statementvoidbroadcastmessage

Cannot implicitly convert type `void' to `bool'

I am having trouble with this script. As of now Unity is telling me that I "Cannot implicitly convert type "void" to "bool. I am trying to end my game with the broadcast of "Game Over". I am using the update to wait for the broadcast and then use update to end my game. Any help would be great and suggestions would also be awesome. I am new to Unity and any help would be appreciated.

 void OnTriggerEnter(Collider other) 
 {
     if (other.gameObject.CompareTag ("OOB")) 
     {
         other.gameObject.SetActive(false);
         SendMessage("Game Over");
         Debug.Log ("Game Over");
     }


 }

 void Update()
 {
     if (SendMessage ("Game Over"))
     {
         Debug.Log("Game Over");
     }
 }

`

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 · Dec 10, 2015 at 11:37 PM 0
Share

You're trying to use Send$$anonymous$$essage in an if condition, but the compiler doesn't know what that means because Send$$anonymous$$essage doesn't return a value.

avatar image BeCzech rutter · Dec 11, 2015 at 02:46 AM 0
Share

Okay, but how do I fix it? Like I said, I'm new.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Holy_Crapf · Dec 11, 2015 at 02:55 AM

If statements check whether the argument you passed is true or false, which means that the argument you pass in has to return a boolean. Send message returns nothing, so its return type is 'void'. I'm not sure if you actually understand what the method SendMessage does, but I'll give you a quick rundown.

SendMessage looks through all MonoBehahaviours on that game object to see if it can find any function by the name of "GameOver". So this means that if you wanted to have a game over sequence, then you could put your code inside of a method called "GameOver".

Here's a link to the Unity Scripting API. If you haven't looked through the tutorials, manual, or api yet, you should definitely do that.

http://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

In void bool dont changing 1 Answer

Weird problem with simple boolean and "if" statement [C#] 0 Answers

Problem with If statement and Collision!? 0 Answers

Bools not changing... 0 Answers

How to turn off/on a collider using a bool variable from another script 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