(20,6): error CS0592: Could use help if anyone willing

getting an error and not sure what it means i am newer to coding. I have very little experience and everything i know is self-taught. Any help would be great i am working on a turret script for a space game since the game broke their scripts for it i am working on my own to make them work again on different models but i am getting a (20,6): error CS0592: Attribute ‘Range’ is not valid on this declaration type. It is only valid on ‘field’ declarations. Also i am not sure if i even did any if this right lol but i am trying.

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

public class TurretMotion : MonoBehaviour
{
    [Header("Turret gameobjects")]
    public Transform turretBase;
    public Transform turretBarrel; 

        [Header("Rotation settings")]
    [Range(0,360)]
    public float rightRotationLimit;
    [Range(0,360)]
    public float leftRotationLimit;
    [Range(0,360)]
    public float elevationRotationLimit;
    [Range(0,75)]
    public float depressionRotationLimit;
    [Range(0,90)]

    private void Update()
    {
        //Get the local direction from the parent to enemy (this works even if the parent moves)
        Vector3 directionToTarget = enemy.position - transform.parent.position;
        float dirAngle = Vector3.Angle(transform.parent.forward, directionToTarget);
      
        //Is Enemy on the left or on the right.
        Vector3 enemyDirectionLocal = transform.parent.InverseTransformPoint(enemy.transform.position);
        float dirX = enemyDirectionLocal.x;

        //Is Enemy on the top or on the bottom.
        Vector3 enemyDirectionLocal = transform.parent.InverseTransformPoint(enemy.transform.position);
        float diry = enemyDirectionLocal.y;

        //Clamping the angle between 180 on the left and 180 on the right.
        if (dirX < 0)
        {
            enemyDetected = Physics.CheckSphere(transform.parent.position, detectionRadius, whatIsEnemy) && Mathf.Abs(dirAngle) < 180.0f;
        }
        else
        {
            enemyDetected = Physics.CheckSphere(transform.parent.position, detectionRadius, whatIsEnemy) && Mathf.Abs(dirAngle) < 180;
        }

        if (enemyDetected)
        {
            Shoot();

             //Setting  LookAt angle.
        Quaternion angle = Quaternion.LookRotation(enemy.position - transform.position);
        //look at target in a smooth transition.
        Quaternion _LookAt = Quaternion.RotateTowards(transform.rotation, angle, 6.0f);
        transform.rotation = _LookAt;
        }
        else
        {
            StopShoot();

            if (noenemyDetected)

                         //Setting  Return angle.
        Quaternion angle = Quaternion.Identity(turretBase.position - transform.position);
        //return to default in a smooth transition.
        Quaternion _ReturnTo = Quaternion.RotateTowards(transform.rotation, angle, 0.0f);
        transform.rotation = _ReturnTo;
        }
    }
}

how would i add in a Get/Set into that?

Each attribute of type Range belongs to a field. For example in your script, the first three Range Attributes limit the range in the Unity editor of your float variables (see https://docs.unity3d.com/6000.0/Documentation/ScriptReference/RangeAttribute.html)rightRotationLimit,leftRotationLimit and elevationRotationLimit between the numbers 0 and 360. The next Range attribute limits the depressionRotationLimit between the numbers 0 and 75.

After that you have one more Range attribute the [Range(0,90)] that is not followed by any float variable declaration. Either you are missing a variable after the attribute, or delete it if there is no variable to constrain.

thanks i over looked i added that last [Range(0,90)] removing it fixed it

For future reference, you don’t need the forum for your own typing mistakes.

You can fix your own typing mistakes. Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. 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 complete error message contains everything you need to know to fix the error yourself.

The important parts of the 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)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

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.