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 yyamiyyugi · Aug 01, 2013 at 05:26 AM · c#

Cannot assign to 'Respawn' because it is a 'method group'?

Hello again, I have yet another problem with the health script I have been trying to write, First off here is my code:

  using UnityEngine;
     using System.Collections;
      
      public class Health : MonoBehaviour 
     {
      
         public float maxHealth = 100.0f ;
         public float curHealth = 100.0f ;
         public GameObject Player;
      
      
         void Start(){
            
         }
      
         void Update(){
      
            if(curHealth < 0){
               curHealth = 0;
            
             }
            if(curHealth > maxHealth){
               curHealth = maxHealth ;
               }
             if(Respawn = true){
              ApplyDamage(-100.0f);
         } 
         }
      
      
         void OnGUI(){
              GUI.Label(new Rect(100,100,100,100), curHealth + "/" + maxHealth);
      
         }
      
          void Respawn(bool boo){
                     Instantiate(Player, new Vector3 (23.21657f, 3.257863f, -0.6684538f), Quaternion.identity);
                     Destroy(Player);    
                   
         }
      
         void ApplyDamage(float damage){
            curHealth -= damage ;
         }
      
               void OnTriggerEnter(Collider other) {
            if(other.gameObject.CompareTag("Zombie")){
               ApplyDamage(10);
               if(curHealth <= 0.0f){
                     //Instantiate(Player, new Vector3 (23.21657f, 3.257863f, -0.6684538f), Quaternion.identity);
                     //Destroy(Player);
                     Respawn(true);
                     
                 }
              }
             
         }
     }
 

Ok so, I am currently able to respawn with this code but my health stays at 0, I tried using curHealth = 100; in the Respawn but it doesn't work, I also tried using ApplyDamage(-100.0f) in it but neither worked, so I went on to add an if statement (currently in the code) to set the health if Respawn = true but i get the error above.

Can someone explain what the error means and possibly help me with a solution to setting my health after respawn?

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 robertbu · Aug 01, 2013 at 05:30 AM 0
Share

Your compiler issue is because comparison use double-equal signs like this: '==', so your code should be:

 if(Respawn == true){
     ApplyDamage(-100.0f);


I don't get how you are doing respawning. Where is this script attached? Do you expect the health of the newly spawned Player to get reset to 100?

avatar image tw1st3d · Aug 01, 2013 at 05:33 AM 0
Share

After that, you're asking if a void is returning as true. Can't do that. $$anonymous$$ake it a public bool and return a bool value.

avatar image yyamiyyugi · Aug 01, 2013 at 03:59 PM 0
Share

@robertbu I had already tried ==, but it then says "Operator '==' cannot be applied to operands of type '$$anonymous$$ethod group' and 'bool'", As far as how I expect it to work, It should create a copy of the player, then destroy the original and set the health of the copy to 100.

@tw1st3d If i make Respawn a public bool then the compiler complains on the if statement that it "Cannot assign to 'Respawn' because it is a 'method group'" still, then in Respawn it complains that "'Health.Respawn(bool)': not all codepaths return a value"

2 Replies

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

Answer by TutiBueno2 · Aug 01, 2013 at 04:11 PM

OK. Line 26 should be:

 if(Respawn == true)
Comment
Add comment · Show 9 · 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 Xtro · Aug 01, 2013 at 04:21 PM 0
Share

No. Respawn's type is void. Can't be used in if block.

avatar image yyamiyyugi · Aug 01, 2013 at 04:58 PM 0
Share

Read my above comment

avatar image TutiBueno2 · Aug 01, 2013 at 05:09 PM 0
Share

If Respawn method is a void, that's another problem. One of the problem was comparing with single '='.

avatar image yyamiyyugi · Aug 03, 2013 at 01:26 AM 0
Share

How do I fix this?

avatar image TutiBueno2 · Aug 03, 2013 at 02:31 AM 0
Share

I really don't see why you have to destroy the player and instantiate it again. You could just change the player position to the one that is hard-coded in your Respawn method. I'll post another code for you.

Show more comments
avatar image
0

Answer by Xtro · Aug 01, 2013 at 04:04 PM

Your "Respawn" is a method and its return type is void. You can't test it in if block which requires a bool value.

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 yyamiyyugi · Aug 01, 2013 at 04:58 PM 0
Share

Read my above comment

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

18 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

Related Questions

turn on off particle system 1 Answer

Hide the ImageTraget in Real world 0 Answers

how to get in game numerical input 1 Answer

How to Avoid Corner paths in A* pathfinding 1 Answer

only detect numerical keyboard input 2 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