error CS1513: } expected

FlädlesuppeLP 26 Reputation points
2021-09-30T21:13:28.91+00:00

I am trying a bit around with Unity and making games with it. But I got an error and don't know what to do. I am not very good in coding so I just watched a few tutorials on YouTube to get it somehow working.
I followed a tutorial on YouTube about "WeaponSwitching" but at some point I got an error that didn't come up in the tutorial. I couldn't find something specific about it that helped me.
The tutorial I watched is from 2017 maybe there are changes that don't allow the code to still work?

This is the tutorial:
https://youtu.be/Dn_BUIVdAPg

The time the error came up:
https://youtu.be/Dn_BUIVdAPg?t=431
7:11

The message in the Unity Console:
Assets\scripts\WeaponSwitching.cs(35,26): error CS1513: } expected

My code:

  1. using UnityEngine;
  2. public class WeaponSwitching : MonoBehaviour
  3. {
  4. public int selectedWeapon = 0;
  5. // Start is called before the first frame update
  6. void Start()
  7. {
  8. SelectWeapon();
  9. }
  10. // Update is called once per frame
  11. void Update()
  12. {
  13. if (Input.GetAxis("Mouse ScrollWheel") > 0f){
  14. if (selectedWeapon >= transfrom.childCount - 1){
  15. selectedWeapon = 0;
  16. }else {
  17. selectedWeapon++;
  18. }
  19. }
  20. if (Input.GetAxis("Mouse ScrollWheel") < 0f){
  21. if (selectedWeapon <= 0){
  22. selectedWeapon = transfrom.childCount - 1;
  23. }else {
  24. selectedWeapon--;
  25. }
  26. }
  27. }
  28. void SelectWeapon (){
  29. in i = 0;
  30. foreach (Transform weapon in transfrom)
  31. {
  32. if(i == selectedWeapon){
  33. weapon.gameObject.SetActive(true);
  34. }else {
  35. weapon.gameObject.SetActive(false);
  36. }
  37. i++;
  38. }
  39. }
  40. }

Code in VisualStudio Code:

136804-code.png

Azure SQL Database
0 comments No comments
{count} votes

Accepted answer
  1. Anurag Sharma 17,586 Reputation points
    2021-10-01T06:54:59.637+00:00

    Hi @FlädlesuppeLP , welcome to Microsoft Q&A forum.

    I copied and compiled the code provided by you and it seems the problem is with line 37 in code provided. You are declaring an integer variable 'i' but 'int' is mentioned as 'in'

    Use this in line 37:

    int i = 0;  
    

    Please let us know if this works or else we can discuss further.

    ----------

    If answer helps you can mark it 'Accept Answer'


2 additional answers

Sort by: Most helpful
  1. Alberto Morillo 33,421 Reputation points MVP
    2021-09-30T22:17:53.75+00:00

    Please every { needs a matching }. Please review all your code and make sure every opening "{" has a closing "}".

    1 person found this answer helpful.

  2. michael loria 1 Reputation point
    2021-12-02T15:47:16.133+00:00

    Having the same problem too, it wants me to put a } where there is one, could anyone help me out? (the screwdriver wants me to add a debugger btw)