I tried to do a recoil and I ended with 23 errors.

I writed this code with this tutorial and something gone wrong and I don’t know what. Before adding [115,116,119,45,48] it work. Please Help

Errors:
Assets\data\Scripts\Weapon.cs(115,33): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\data\Scripts\Weapon.cs(115,40): error CS1031: Type expected
Assets\data\Scripts\Weapon.cs(115,40): error CS8124: Tuple must contain at least two elements.
Assets\data\Scripts\Weapon.cs(115,40): error CS1026: ) expected
Assets\data\Scripts\Weapon.cs(115,40): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(115,49): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a ‘new’ expression)
Assets\data\Scripts\Weapon.cs(115,62): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(115,63): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\data\Scripts\Weapon.cs(115,69): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(116,33): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\data\Scripts\Weapon.cs(116,42): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(116,86): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable’s identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
Assets\data\Scripts\Weapon.cs(116,87): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a ‘new’ expression)
Assets\data\Scripts\Weapon.cs(116,100): error CS1002: ; expected
Assets\data\Scripts\Weapon.cs(116,100): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(116,101): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\data\Scripts\Weapon.cs(116,109): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(119,9): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\data\Scripts\Weapon.cs(119,25): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(119,36): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a ‘new’ expression)
Assets\data\Scripts\Weapon.cs(119,49): error CS1022: Type or namespace definition, or end-of-file expected
Assets\data\Scripts\Weapon.cs(119,50): error CS0116: A namespace cannot directly contain members such as fields or methods
Assets\data\Scripts\Weapon.cs(119,58): error CS1022: Type or namespace definition, or end-of-file expected

and code:

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Security.Cryptography;
using UnityEngine;

namespace Com.deduwa.SimpleHostile
{
    public class Weapon : MonoBehaviour
    {
        #region Variables

        public Gun[] loadout;
        public Transform weaponParent;
        public GameObject bulletholePrefab;
        public LayerMask canBeShot;
        public bool gunEnabled;

        private float currentCooldown;
        private int currentIndex;
        private GameObject currentWeapon;

        #endregion

        #region Monobehaviour Callbacks
        void Start()
        {

        }


        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Alpha1)) Equip(0);
            if (currentWeapon != null)
            {
                Aim(Input.GetMouseButton(1));
                if (Input.GetMouseButtonDown(0) && currentCooldown <= 0)
                {
                    Shoot();
                }

                //weapon position elasticity
                currentWeapon.transform.localRotation = Quaternion.Lerp(currentWeapon.transform.localRotation, Quaternion.identity, Time.deltaTime * 4f);

                //cooldown
                if (currentCooldown > 0) currentCooldown -= Time.deltaTime;
            }
        }

        #endregion

        #region Private Methods
        void Equip(int p_ind)
        {
            if (currentWeapon != null) Destroy(currentWeapon);

            currentIndex = p_ind;

            GameObject t_newWeapon = Instantiate(loadout[p_ind].prefab, weaponParent.position, weaponParent.rotation, weaponParent);
            t_newWeapon.transform.localPosition = Vector3.zero;
            t_newWeapon.transform.localEulerAngles = Vector3.zero;

            currentWeapon = t_newWeapon;
        }

        void Aim(bool p_isAiming)
        {
            Transform t_anchor = currentWeapon.transform.Find("Anchor");
            Transform t_state_ads = currentWeapon.transform.Find("States/ADS");
            Transform t_state_hip = currentWeapon.transform.Find("States/Hip");

            if (p_isAiming)
            {
                //aim
                t_anchor.position = Vector3.Lerp(t_anchor.position, t_state_ads.position, Time.deltaTime * loadout[currentIndex].aimSpeed);

            }
            else
            {
                //hip
                t_anchor.position = Vector3.Lerp(t_anchor.position, t_state_hip.position, Time.deltaTime * loadout[currentIndex].aimSpeed);
            }

        }

        void Shoot()
        {
            Transform t_spawn = transform.Find("Kamery/PCam");

            //bloom
            Vector3 t_bloom = t_spawn.position + t_spawn.forward * 1000f;
            t_bloom += Random.Range(-loadout[currentIndex].bloom, loadout[currentIndex].bloom) * t_spawn.up;
            t_bloom += Random.Range(-loadout[currentIndex].bloom, loadout[currentIndex].bloom) * t_spawn.right;
            t_bloom -= t_spawn.position;
            t_bloom.Normalize();



            //raycast

            RaycastHit t_hit = new RaycastHit();
            if (Physics.Raycast(t_spawn.position, t_spawn.forward, out t_hit, 1000f, canBeShot))
            {
                GameObject t_newHole = Instantiate(bulletholePrefab, t_hit.point + t_hit.normal * 0.001f, Quaternion.identity) as GameObject;
                t_newHole.transform.LookAt(t_hit.point + t_hit.normal);
                Destroy(t_newHole, 10f);
            }
        }
    }
        //gun fx
      
  
        currentWeapon.transform.Rotate(-loadout[currentIndex].recoil, 0, 0);
        currentWeapon.transform.position -= currentWeapon.transform.forward * loadout[currentIndex].kickback;

        //cooldown
        currentCooldown = -loadout[currentIndex].firerate;


    #endregion
}

You close out the class with the closing brace on line 111. What class and method are lines 115 through 119 supposed to be in?

nevermind, brace 110 and 111 supposed to be at the end, anyway thanks for help

1 Like