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:
- using UnityEngine;
- public class WeaponSwitching : MonoBehaviour
- {
- public int selectedWeapon = 0;
- // Start is called before the first frame update
- void Start()
- {
- SelectWeapon();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetAxis("Mouse ScrollWheel") > 0f){
- if (selectedWeapon >= transfrom.childCount - 1){
- selectedWeapon = 0;
- }else {
- selectedWeapon++;
- }
- }
- if (Input.GetAxis("Mouse ScrollWheel") < 0f){
- if (selectedWeapon <= 0){
- selectedWeapon = transfrom.childCount - 1;
- }else {
- selectedWeapon--;
- }
- }
- }
- void SelectWeapon (){
- in i = 0;
- foreach (Transform weapon in transfrom)
- {
- if(i == selectedWeapon){
- weapon.gameObject.SetActive(true);
- }else {
- weapon.gameObject.SetActive(false);
- }
- i++;
- }
- }
- }
Code in VisualStudio Code: