Search Unity

Error: Cannot convert method group 'x' to non-delegate type 'bool'.

Discussion in 'Scripting' started by Nobl4e, Jul 30, 2019.

  1. Nobl4e

    Nobl4e

    Joined:
    Jul 25, 2019
    Posts:
    3
    Cannot convert method group 'IsGrounded' to non-delegate type 'bool'. Did you intend to invoke the method?

    Please help me, how do I fix this?
    Code (CSharp):
    1.  
    2.  
    3.  
    4. using System.Collections;
    5. using UnityEngine;
    6.  
    7. public class WallRun : MonoBehaviour {
    8.  
    9.     public bool isWallR = false;
    10.     public bool isWallL = false;
    11.     private RaycastHit hitR;
    12.     private RaycastHit hitL;
    13.     private int jumpCount = 0;
    14.     public PlayerMovementController cc;
    15.     public Rigidbody rb;
    16.     public Transform cameraEffect;
    17.     public Animator anim;
    18.     public bool canJump;
    19.  
    20.  
    21. void Start () {
    22.      
    23. }
    24.  
    25.     void Update()
    26.     {
    27.         if (cc.IsGrounded())
    28.         {
    29.             jumpCount = 0;
    30.             isWallL = false;
    31.             isWallR = false;
    32.         }
    33.         if (isWallR == true && isWallL == false)
    34.         {
    35.            
    36.             anim.SetBool("Left", true);
    37.         }
    38.         if (isWallR == false)
    39.         {
    40.            
    41.             anim.SetBool("Left", false);
    42.         }
    43.         if (isWallL == false)
    44.         {
    45.            
    46.             anim.SetBool("Right", false);
    47.         }
    48.         if (isWallR == false && isWallL == true)
    49.         {
    50.          
    51.             anim.SetBool("Right", true);
    52.         }
    53.  
    54.         if (canJump == true && Input.GetKeyDown(KeyCode.Space))
    55.         {
    56.             rb.AddForce(Vector3.up * 100, ForceMode.Impulse);
    57.             if (isWallL == true)
    58.             {
    59.                 Vector3 force = this.transform.right * 200;
    60.                 rb.AddForceAtPosition(force, this.transform.position, ForceMode.Impulse);
    61.             }
    62.             if (isWallR == true)
    63.             {
    64.                 Vector3 force = -this.transform.right * 200;
    65.                 rb.AddForceAtPosition(force, this.transform.position, ForceMode.Impulse);
    66.             }
    67.         }
    68.        
    69.         if (cc.IsGrounded)
    70.         {
    71.             if (Physics.Raycast(transform.position, transform.right, out hitR, 1))
    72.             {
    73.                 if (hitR.transform.tag == "Wall")
    74.                 {
    75.                     canJump = true;
    76.                     isWallR = true;
    77.                     isWallL = false;
    78.                     jumpCount += 1;
    79.  
    80.                     rb.useGravity = false;
    81.                 }
    82.             }
    83.             if (!Physics.Raycast(transform.position, transform.right, out hitR, 1))
    84.             {
    85.                    
    86.                     isWallR = false;
    87.                     jumpCount += 1;
    88.                 if (isWallL == false)
    89.                 {
    90.                     canJump = false;
    91.                     rb.useGravity = true;
    92.                 }
    93.             }
    94.             if (Physics.Raycast(transform.position, -transform.right, out hitL, 1))
    95.             {
    96.                 if (hitL.transform.tag == "Wall")
    97.                 {
    98.                     canJump = true;
    99.                     isWallL = true;
    100.                     jumpCount += 1;
    101.                     rb.useGravity = false;
    102.                 }
    103.             }
    104.             if (!Physics.Raycast(transform.position, -transform.right, out hitL, 1))
    105.             {
    106.                
    107.                 isWallL = false;
    108.                 jumpCount += 1;
    109.                 if (isWallR == false)
    110.                 {
    111.                     canJump = false;
    112.                     rb.useGravity = true;
    113.                 }
    114.             }
    115.         }
    116.     }
    117. }
    I want to use a part of a script that I wrote and is in the project.
    The error is at 66:16, please help and thank you!
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    It means that your code
    cc.IsGrounded
    doesn't return a bool as you have it typed.

    Is "IsGrounded" a method? Should it be
    cc.IsGrounded()
    ?
     
    astechnolabs and aradormania like this.
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    If IsGrounded is a method, you need the () after it, just like you have earlier in the script
     
  4. Nobl4e

    Nobl4e

    Joined:
    Jul 25, 2019
    Posts:
    3
    Thank you so much, I didnt realize, thanks alot!
     
  5. Nobl4e

    Nobl4e

    Joined:
    Jul 25, 2019
    Posts:
    3
    Thanks for the help! Im new to this and didnt realize.