Search Unity

error CS1519: Invalid token 'void' in class, struct, or interface member declaration

Discussion in 'Editor & General Support' started by SimonDziak, Sep 13, 2019.

Thread Status:
Not open for further replies.
  1. SimonDziak

    SimonDziak

    Joined:
    Apr 26, 2019
    Posts:
    5
    Hello,

    I'm having a problem with Unity 2019.2.5f. The console is throwing an error described in title
    Assets\Controller.cs(12,5): error CS1519: Invalid token 'void' in class, struct, or interface member declaration.

    Here is my code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Controller : MonoBehaviour
    4. {
    5.     private Rigidbody rb;
    6.     public float speed;
    7.     public Camera
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         float horizontal = (Input.GetAxis("Horizontal") * speed) * Time.deltaTime;
    18.         float vertical = (Input.GetAxis("Vertical") * speed) * Time.deltaTime;
    19.  
    20.         transform.Translate(vertical, 0, horizontal);
    21.  
    22.     }
    23. }
    24.  
    I tried reinstalling the Unity Version alongside with reinstalling Visual Studio. Both are on the latest versions.
     
  2. SimonDziak

    SimonDziak

    Joined:
    Apr 26, 2019
    Posts:
    5
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    SimonDziak likes this.
  4. SimonDziak

    SimonDziak

    Joined:
    Apr 26, 2019
    Posts:
    5
    - fixed it.
    Line 7 was missing a ';'

    :)
     
  5. SimonDziak

    SimonDziak

    Joined:
    Apr 26, 2019
    Posts:
    5
    thank you. noticed it right before
     
    karl_jones likes this.
  6. leticiabovinorodriguez

    leticiabovinorodriguez

    Joined:
    May 1, 2020
    Posts:
    1
    Hi! I am also having the same error CS1519: Invalid token 'void' in class, struct, or interface member declaration.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class MainCard : MonoBehaviour{

    [SerializeField] private SceneController controller;
    [SerializeField] private GameObject Card_Back;

    public void OnMouseDown()
    {
    if(Card_Back.activeSelf && controller.canReveal)
    {
    Card_Back.SetActive(false);
    controller.CardRevealed(this);
    }
    }

    private int _id;
    public int id
    {
    get { return _id; }
    }

    public void ChangeSprite(int id, Sprite image)
    {
    _id = id;
    GetComponent<SpriteRenderer>().sprite = image; //This gets the sprite renderer component and changes the property of its sprite!
    }

    Public void Unreveal()
    {
    Card_Back.SetActive(true);
    }

    }
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    "Public" should be lowercase, like this: "public".
     
  8. antonlupor

    antonlupor

    Joined:
    Jun 17, 2020
    Posts:
    4
    I am having the same error too:
    Assets\Skripte\Movement.cs(10,34): error CS1519: Invalid token ';' in class, struct, or interface member declaration

    What did I wrong?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movement : MonoBehaviour
    6. {
    7.     public float MovementSpeed = 1;
    8.     public float JumpForce = 1;
    9.  
    10.     private Rigidbody2D_rigidbody;
    11.  
    12.     private void Start()
    13.     {
    14.         _rigidbody = GetComponent<Rigidbody2D>();
    15.     }
    16.  
    17.  
    18.     private void Update()
    19.     {
    20.        var movement = Input.GetAxis("Horizontal");
    21.        transform.position += new Vector3(movement,0,0) * Time.deltaTime * MovementSpeed;
    22.  
    23.        if(input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f)
    24.        {
    25.        _rigidbody.AddForce(new Vector2(0,JumpForce), ForceMode2D.Impulse);
    26.  
    27.        }
    28.  
    29.  
    30.     }
    31. }
    32.  
     
  9. anton040

    anton040

    Joined:
    Aug 13, 2020
    Posts:
    1
    Näyttökuva 2020-8-13 kello 10.26.55.png
    how can I fix this
    my problem:
    Assets/playermovement.cs(6,26): error CS1519: Invalid token ';' in class, struct, or interface member declaration
     
  10. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    This is invalid syntax:
    Code (CSharp):
    1. public.Rigidbody = rb;
    Should de declared as:
    Code (CSharp):
    1. public Rigidbody rb;
     
  11. leroitheoneandonly

    leroitheoneandonly

    Joined:
    Aug 23, 2020
    Posts:
    2
    upload_2020-8-23_20-31-40.png
    How can i FIx this?
    My problem:
    Assets\Shooting.cs(9,24): error CS1519: Invalid token ';' in class, struct, or interface member declaration
     
  12. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Line 9:
    You didn't give "BulletPrefab" a type. (Did you mean
    public GameObject BulletPrefab
    ?)
     
  13. leroitheoneandonly

    leroitheoneandonly

    Joined:
    Aug 23, 2020
    Posts:
    2
    Yes that fixed it, Thank you
     
  14. FireBlazingDev

    FireBlazingDev

    Joined:
    Sep 28, 2020
    Posts:
    4
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerScripts : MonoBehaviour {

    private Rigidbody2D myRigidbody;

    public float movementSpeed;

    private bool facingRight;

    // Start is called before the first frame update
    void Start()(

    myRigidbody = GetComponent<Rigidbody2D> ();
    facingRight = true;
    )

    // Update is called once per frame
    void Update() {

    }

    void FixedUpdate(){
    float horizontal = Input.GetAxis ("Horizontal");
    //Debug.Log (horizontal);
    HandleMovement(horizontal);
    }

    private void HandleMovement(float horizontal)(
    myRigidbody.velocity = new Vector2 (horizontal * movementSpeed, myRigidbody.velocity.y);
    {
    }



    what did i do wrong????????????????????
     
  15. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    First:
    • Don't hijack an existing topic with a different question. Create your own topic instead.
    • Use code tags when posting code.
    • Describe the problem you're having in detail; "What did I do wrong" doesn't tell anything. What is supposed to be happening, and what is actually happening? If you're getting any error messages, copy/paste exactly what they say as well.
    In your case, you have a syntax error after the
    Start
    method. You used parentheses to declare the method body...
    Code (CSharp):
    1. void Start() (
    2.  
    3. )
    ...When they should be curly braces:
    Code (CSharp):
    1. void Start() {
    2.  
    3. }
    You also have a similar issue in your
    HandleMovement
    method, where you put the logic inside of the method arguments instead of the method body.
     
  16. FireBlazingDev

    FireBlazingDev

    Joined:
    Sep 28, 2020
    Posts:
    4
    theese are the errors
    Assets\Scripts\Player Scripts\PlayerScript.cs(14,17): error CS1002: ; expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(16,21): error CS8124: Tuple must contain at least two elements.
    Assets\Scripts\Player Scripts\PlayerScript.cs(16,21): error CS1026: ) expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(16,21): error CS1519: Invalid token '=' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(16,49): error CS1519: Invalid token '(' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(16,50): error CS8124: Tuple must contain at least two elements.
    Assets\Scripts\Player Scripts\PlayerScript.cs(16,51): error CS1519: Invalid token ';' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(17,21): error CS1519: Invalid token '=' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(25,23): error CS1002: ; expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,26): error CS8124: Tuple must contain at least two elements.
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,26): error CS1026: ) expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,26): error CS1519: Invalid token '=' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,42): error CS1519: Invalid token '(' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,43): error CS1031: Type expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,43): error CS8124: Tuple must contain at least two elements.
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,43): error CS1026: ) expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(26,43): error CS1519: Invalid token '"Horizontal"' in class, struct, or interface member
    Assets\Scripts\Player Scripts\PlayerScript.cs(28,34): error CS1001: Identifier expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(29,5): error CS1519: Invalid token ')' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(31,50): error CS1002: ; expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(32,30): error CS8124: Tuple must contain at least two elements.
    Assets\Scripts\Player Scripts\PlayerScript.cs(32,30): error CS1026: ) expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(32,30): error CS1519: Invalid token '=' in class, struct, or interface member declaration
    Assets\Scripts\Player Scripts\PlayerScript.cs(32,95): error CS1001: Identifier expected
    Assets\Scripts\Player Scripts\PlayerScript.cs(34,1): error CS1022: Type or namespace definition, or end-of-file expected

    Theese are all of my errors, they are 25 and in order. I am also new to unity. Sorry if i did anything that is very stupid.
     
  17. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    All of these should disappear after fixing the syntax errors mentioned above.
     
  18. FireBlazingDev

    FireBlazingDev

    Joined:
    Sep 28, 2020
    Posts:
    4
    All of the errors have been fixed :D i remembered that i put a dot in the code that broke it lol. Thanks for the help man! i rlly owe u one :D
     
  19. skillij

    skillij

    Joined:
    Jul 30, 2020
    Posts:
    1
    Assets\Scripts\PlayerController.cs(11,21): error CS1519: Invalid token ';' in class, struct, or interface member declaration

    i dont know what i do wrong i new in unity and this is the tutorial Roll a Ball and the scripts looks so:
    ps:pls tell me what is wrong




    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class PlayerController : MonoBehaviour
    {
    private Rigidbody rb;
    private float movementX;
    private float movementY;

    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    void onMove(InputValue movementValue)
    {
    Vector2 movementVector = movementValue.Get<Vector2>();

    movementX = movementVector.x;
    movementY = movementVector.y;
    }

    void FixedUptade()
    {
    Vector3 movement = new Vector3(movementX, 0.0f, movementY);

    rb.AddForce(movement);
    }
    }
     
  20. Lucky8723

    Lucky8723

    Joined:
    Jan 4, 2021
    Posts:
    1
    Hello,

    I'm having a problem with Unity 2019.2.5f. The console is throwing an error described in title
    Assets\Controller.cs(12,5): error CS1519: Invalid token 'void' in class, struct, or interface member declaration.

    Here is my code:


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour
    {
    private Rigidbody2D rb;
    public float speed;
    public float jumpForce;
    private float moveInput;

    private bool isGrounded;
    public Transform feetPos;
    public float checkRadius;
    public LayerMask whatIsGround;

    private float jumpTimeCounter;
    public float jumpTime;
    private bool isJumping;


    private Animator anim;


    void Start()
    {
    anim = GetComponent<Animator>();
    rb = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
    moveInput = Input.GetAxisRaw("Horizontal");
    rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
    }

    if (moveInput == 0)
    {
    anim.SetBool("isRunning", false);
    }
    else {
    anim.SetBool("isRunning", true);
    }



    void Update()
    {
    isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);

    if (moveInput > 0)
    {
    transform.eulerAngles = new Vector3(0, 0, 0);
    }
    else if (moveInput < 0)
    {
    transform.eulerAngles = new Vector3(0, 180, 0);
    }

    if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
    {
    isJumping = true;
    jumpTimeCounter = jumpTime;
    rb.velocity = Vector2.up * jumpForce;
    }

    if(Input.GetKey(KeyCode.Space) && isJumping == true){

    if(jumpTimeCounter > 0){
    rb.velocity = Vector2.up * jumpForce;
    jumpTimeCounter -= Time.deltaTime;
    } else{
    isJumping = false;
    }


    }
    if (Input.GetKeyUp(KeyCode.Space))
    {
    isJumping = false;
    }




    }


    }
     
  21. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    JeffDUnity3D likes this.
  22. gamecreate001

    gamecreate001

    Joined:
    Nov 19, 2020
    Posts:
    3
    How do I fix this error?
    Error CS1519 Invalid token 'else' in class, struct, or interface member declaration



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    enum Direction {
    LEFT,
    RIGHT
    }

    public class PlayerScript : MonoBehaviour {

    private Animator anim;
    private AudioSource audioManager;
    private Direction dir = Direction.RIGHT;

    public GameObject missle;
    public ParticleSystem rightMuzzle, leftMuzzle, rightFire, leftFire, boost;

    public Transform leftArm, rightArm;
    public Transform misslePoint;

    public Light leftLight, rightLight;

    public float speed = 4f;

    private ParticleSystem.EmissionModule right_Muzzle_Emission, left_Muzzle_Emission,
    right_Fire_Emission, left_Fire_Emission, BoostMain;

    private ParticleSystem.MainModule boostMain;

    private Rigidbody myBody;
    private ConstantForce constForce;

    void Awake() {
    anim = GetComponentInChildren<Animator>();

    audioManager = GetComponent<AudioSource>();

    myBody = GetComponent<Rigidbody>();
    constForce = myBody.GetComponent<ConstantForce>();

    right_Muzzle_Emission = rightMuzzle.emission;
    left_Muzzle_Emission = leftMuzzle.emission;
    right_Fire_Emission = rightFire.emission;
    left_Fire_Emission = leftFire.emission;

    right_Muzzle_Emission.rateOverTime = 0f;
    left_Muzzle_Emission.rateOverTime = 0f;
    right_Fire_Emission.rateOverTime = 0f;
    left_Fire_Emission.rateOverTime = 0f;

    boostMain = boost.main;

    }

    void FixedUpdate() {
    if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
    if (!LeanTween.isTweening(gameObject)) {

    if (isGrounded ())
    anim.Play("Walk");
    else
    anim.Play("Idle");

    if (dir != Direction.LEFT) {
    LeanTween.rotateAroundLocal(gameObject, Vector3.up, 180f, 0.3f).setOnComplete(TurnLeft);
    } else {
    transform.Translate (Vector3.forward * speed * Time.deltaTime);
    }
    }
    } else if(Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D)) {
    if (!LeanTween.isTweening(gameObject)) {

    if (isGrounded())
    anim.Play("Walk");
    else
    anim.Play("Idle");

    if (dir != Direction.RIGHT) {
    LeanTween.rotateAroundLocal(gameObject, Vector3.up, -180f, 0.3f).setOnComplete(TurnRight);
    } else {
    transform.Translate(Vector3.forward * speed * Time.deltaTime);
    }
    }
    } else {
    anim.Play("Idle");
    }
    }

    bool isGrounded() {
    return Physics.Raycast (transform.position = transform.forward * 0.4f +
    transform.up * 0.1f, Vector3.down, 0.1f);
    }

    void TurnLeft() {
    transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
    dir = Direction.LEFT;
    }

    void TurRight() {
    transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
    dir = Direction.RIGHT;
    }

    } // class
     
  23. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    JeffDUnity3D likes this.
  24. idas1234

    idas1234

    Joined:
    Feb 3, 2021
    Posts:
    1
    Ihave a problem with this:



    using UnityEngine;

    public class PlayerCollision : MonoBehaviour{

    public PlayerMovment;



    void OnCollisionEnter (collision collisionInfo)
    {
    if (collisionInfo.collider.tag "Obstacle")
    {
    Debug.Log("yeet!");
    }


    }

    }
     
  25. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    JeffDUnity3D likes this.
  26. PremixedLlama75

    PremixedLlama75

    Joined:
    Feb 4, 2021
    Posts:
    1
    I'm getting this error.
    Assets\Enemy.cs(6,5): error CS1519: Invalid token '{' in class, struct, or interface member declaration
    Here is my code
    using UnityEngine;
    public class Enemy : MonoBehaviour
    {

    private void OnCollisionEnter2D(Collision2D collision);
    {
    Bird bird = collision.collider.GetComponent<Bird>();
    if (bird != null);
    {
    destroy(gameObject);
    }
    }
    }
     
  27. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Please don't reply to old posts. Start your own, its Free, and it's the forum rules.

    WHEN YOU POST, read these notes first:

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    How to understand errors in general:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
    JeffDUnity3D likes this.
  28. P5_eicheryves

    P5_eicheryves

    Joined:
    Apr 3, 2021
    Posts:
    1
    I have the
    error CS1519: Invalid token '{' in class, struct, or interface member declaration
    i dont now the problem




    [code = CSharp]


    using System.Collections;
    using System.Collections.Generic;
    Verwenden von System.Diagnostics;
    mit UnityEngine;

    öffentliche Klasse LevelGenerator: MonoBehaviour {

    Spieler der öffentlichen Klasse; {

    private statische LevelGenerator-Instanz;
    private const float PLAYER_DISTANCE_SPAWN_LEVEL_PART = 200f;

    [SerializeField] private Transform pfTestingPlatform;
    [SerializeField] private Transform levelPart_Start;
    [SerializeField] private List <Transform> levelPartEasyList;
    [SerializeField] private List <Transform> levelPartMediumList;
    [SerializeField] private List <Transform> levelPartHardList;
    [SerializeField] private List <Transform> levelPartImpossibleList;
    [SerializeField] privater Player-Player;



    private enum Schwierigkeit {
    Einfach,
    Mittel,
    Schwer,
    Unmöglich,
    }}

    private Vector3 lastEndPosition;
    private int levelPartsSpawned;



    private void Awake () {
    Instanz = dies;
    lastEndPosition = levelPart_Start.Find ("EndPosition"). position;

    if (pfTestingPlatform! = null) {
    Debug.Log ("Verwenden der Debug-Testplattform!");
    }}

    int StartingSpawnLevelParts = 5;
    for (int i = 0; i <StartingSpawnLevelParts; i ++) {
    SpawnLevelPart ();
    }}
    }}

    private void Update () {
    if (Vector3.Distance (player.GetPosition (), lastEndPosition) <PLAYER_DISTANCE_SPAWN_LEVEL_PART) {
    // Einen anderen Level-Teil erzeugen
    SpawnLevelPart ();
    }}
    }}

    private void SpawnLevelPart () {
    List <Transform> difficLevelPartList;
    switch (GetDifficulty ()) {
    Standard:
    case Difficulty.Easy: difficLevelPartList = levelPartEasyList; Unterbrechung;
    case Difficulty.Medium: difficLevelPartList = levelPartMediumList; Unterbrechung;
    case Difficulty.Hard: difficLevelPartList = levelPartHardList; Unterbrechung;
    case Difficulty.Impossible: difficLevelPartList = levelPartImpossibleList; Unterbrechung;
    }}

    Transform selectedLevelPart = SchwierigkeitLevelPartList [Random.Range (0, SchwierigkeitLevelPartList.Count)];

    if (pfTestingPlatform! = null) {
    selectedLevelPart = pfTestingPlatform;
    }}

    Transform lastLevelPartTransform = SpawnLevelPart (selectedLevelPart, lastEndPosition);
    lastEndPosition = lastLevelPartTransform.Find ("EndPosition"). position;
    levelPartsSpawned ++;
    }}

    private Transform SpawnLevelPart (Transform levelPart, Vector3 spawnPosition) {
    Transform levelPartTransform = Instantiate (levelPart, spawnPosition, Quaternion.identity);
    return levelPartTransform;
    }}

    private Schwierigkeit GetDifficulty () {
    if (levelPartsSpawned> = 19) gibt Difficulty.Impossible zurück;
    if (levelPartsSpawned> = 14) gibt Difficulty.Hard zurück;
    if (levelPartsSpawned> = 7) gibt Difficulty.Medium zurück;
    return Difficulty.Easy;
    }}

    public static int GetLevelPartsSpawned () {
    return instance.levelPartsSpawned;
    }}

    öffentliche Überschreibungszeichenfolge ToString ()
    {
    return base.ToString ();
    }}

    public override bool Equals (Objekt obj)
    {
    return base.Equals (obj);
    }}

    public override int GetHashCode ()
    {
    return base.GetHashCode ();
    }}


    private Zeichenfolge GetDebuggerDisplay ()
    {
    return ToString ();
    }}
    }}
    [/Code]
     
  29. phamdothanhsang

    phamdothanhsang

    Joined:
    May 17, 2021
    Posts:
    1
    Assets\meleeScript.cs(9,27): error CS1519: Invalid token ';' in class, struct, or interface member declaration

    Here is my code



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class meleeScript : MonoBehaviour
    {
    public float damage;
    public float knockBack;
    public knockBackRadius;
    public float meleeRate;

    float nextMelee;

    int shootableMask;

    Animator myAnim;
    PlayerController myPC;
    // Start is called before the first frame update
    void Start()
    {
    shootableMask = LayerMask.GetMask("Shootable");
    myAnim = transform.root.GetComponent<Animator>();
    myPC = transform.root.GetComponent<PlayerController>();
    nextMelee = 0f;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    float melee = Input.GetAxis("Fire2");

    if(melee > 0 && nextMelee < Time.time && !(myPC.getRunning()))
    {
    myAnim.SetTrigger("gunMelee");
    nextMelee = Time.time + meleeRate;

    //do damage
    Collider[] attacked = Physics.OverlapSphere(transform.position, knockBackRadius, shootableMask);
    }
    }
    }
     
  30. Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class meleeScript : MonoBehaviour
    6. {
    7. public float damage;
    8. public float knockBack;
    9. public knockBackRadius;
    10. public float meleeRate;
    11.  
    12. float nextMelee;
    13.  
    14. int shootableMask;
    15.  
    16. Animator myAnim;
    17. PlayerController myPC;
    18. // Start is called before the first frame update
    19. void Start()
    20. {
    21. shootableMask = LayerMask.GetMask("Shootable");
    22. myAnim = transform.root.GetComponent<Animator>();
    23. myPC = transform.root.GetComponent<PlayerController>();
    24. nextMelee = 0f;
    25. }
    26.  
    27. // Update is called once per frame
    28. void FixedUpdate()
    29. {
    30. float melee = Input.GetAxis("Fire2");
    31.  
    32. if(melee > 0 && nextMelee < Time.time && !(myPC.getRunning()))
    33. {
    34. myAnim.SetTrigger("gunMelee");
    35. nextMelee = Time.time + meleeRate;
    36.  
    37. //do damage
    38. Collider[] attacked = Physics.OverlapSphere(transform.position, knockBackRadius, shootableMask);
    39. }
    40. }
    41. }
    Please use code tags like this, above.
    Please open your own thread.
    public knockBackRadius;
    you forgot the type.
     
  31. greuzer

    greuzer

    Joined:
    Jun 9, 2021
    Posts:
    2
    Assets\PlayerMovement1.cs(8,26): error CS1519: Invalid token '=' in class, struct, or interface member declaration

    My Code



    using UnityEngine;

    public class PlayerMovement1 : MonoBehaviour {

    // This is a reference to a Rigidbody component called "rb"
    public Rigidbody rb;

    private forwardforce = 200f;

    public global::System.Single Forwardforce { get => forwardforce; set => forwardforce = value; }

    // We marked this as "Fixed"Update because we
    // are using it to mess with physics.
    void FixedUpdate()
    {
    // Add a forward force


    global::System.Object p = rb.Addforce(0, 0, Forwardforce * Time.deltaTime);

    if (!Input.GetKey("d"))
    {
    global::System.Object p1 = rb.AddForce(500 * Time.deltaTime);
    }
    }
    }
     
  32. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Please STOP replying to old threads when you have a simple typo.

    Instead, learn how to fix it. Here's how:

    Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The important parts of an error message are:
    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
    Joe-Censored likes this.
  33. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please don't multipost, already answered here https://forum.unity.com/threads/ass...en-in-class-struct-or-interface-memb.1123294/
     
    Joe-Censored likes this.
  34. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Once again, please STOP replying to old threads when you have a simple typo.

    Instead, learn how to fix it. Here's how:

    Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The important parts of an error message are:
    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
Thread Status:
Not open for further replies.