Search Unity

Bug } expected issue

Discussion in 'Scripting' started by Krazo, Mar 24, 2021.

  1. Krazo

    Krazo

    Joined:
    Mar 24, 2021
    Posts:
    3
    Im Stuck on this as it says I'm missing a } but am unsure as to where to put it. any help? upload_2021-3-24_23-13-22.png
    upload_2021-3-24_23-13-43.png
     
  2. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
    You are missing the opening and closing brace for the class body. Add ("{" line 6, "}" line 41)
     
    Putcho and Joe-Censored like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Putcho likes this.
  4. Krazo

    Krazo

    Joined:
    Mar 24, 2021
    Posts:
    3
    Im sorry, I'm very new to unity and C# and I've added it and the errors are still there, any fixes. sorry.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerAttack : MonoBehaviour
    6.  
    7.      public Camera cam;
    8.      public GameObject Hand;
    9.      public Weapon myWeapon;
    10.      Animation handAnim;
    11.  
    12.      void Start() {
    13.         handAnim = Hand.GetComponent<Animator>();
    14.          myWeapon = Hand.GetComponentInChildren<Weapon>();
    15.      }
    16.      
    17.    
    18.      void Update() {
    19.        if(Input.GetMouseButtonUp(0))
    20.        {
    21.           DoAttack();
    22.        }
    23.      }
    24.    
    25.      private void DoAttack()
    26.      {
    27.  
    28.          Ray ray = cam.ScreenPointToRay(Input.mousePosition);
    29.          RaycastHit hit;
    30.  
    31.          if(Physics.Raycast(ray , out hit, myWeapon.attackRange))
    32.          {
    33.  
    34.             if(hit.collider.tag = "Enemy")
    35.             {
    36.                 EnemyHealth. eHealth = hit.collider.GetComponent<EnemyHealth>();
    37.                 eHealth.TakeDamage(myWeapon.attackDamage);
    38.             }
    39.          }  
    40.      }
    41. //end o class ("{"line 6,"}" line 41")
     
  5. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    yeah but where is "{" on line 6
     
  6. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    and why you copy and paste ("{" line 6, "}" line 41) on line 41
    that is not what spryx want you to do
    you write: { ,at line 6 and, } at line 41
     
  7. Krazo

    Krazo

    Joined:
    Mar 24, 2021
    Posts:
    3
    thanks
     
    Putcho likes this.