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;
}
}
}