Public Variable Not Displaying in Inspector

I have an attack script for my enemies, I wanted to make the range of the raycast editable in the inspector, but for some reason, it’s not showing up in the inspector.
Here’s my script,

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

public class BitingMold : MonoBehaviour
{
    public Animator animator;
    public GameObject attackTrigger;
    public EnemyMover mover;
    public EnemyCreator enemy;
    public bool isAttacking;
    private float speed, baseSpeed;
    public float rayRange = 0;
    public LayerMask playerLayer;
    public Player player;
    private void Start()
    {
        enemy = this.GetComponent<EnemyCreator>();
        player = FindObjectOfType<Player>();
        attackTrigger = GameObject.Find("EnemyAttackTrigger");
        attackTrigger.SetActive(false);
        mover = this.GetComponent<EnemyMover>();
        baseSpeed = enemy.speed;
        animator = this.GetComponent<Animator>();
       
    }
    private void Update()
    {
        RaycastHit2D info = Physics2D.Raycast(transform.position, mover.isRight ? Vector2.right : Vector2.left, rayRange, playerLayer);
        if (info.collider != null)
        {
            if(!this.GetComponentInParent<EnemyCreator>().isDead && !isAttacking && !player.isDead)
            {
                StartCoroutine(Attack());
            }
        }
    }
    IEnumerator Attack()
    {
        if (!this.GetComponentInParent<EnemyCreator>().isDead)
        {
            enemy.speed = 0.1f;
            isAttacking = true;
            animator.SetBool("isAttacking", true);
            yield return new WaitForSeconds(0.5f);
            attackTrigger.SetActive(true);
            yield return new WaitForSeconds(0.25f);
            animator.SetBool("isAttacking", false);
            if (attackTrigger != null)
            {
                attackTrigger.SetActive(false);
            }
                isAttacking = false;
            enemy.speed = baseSpeed;
        }
    }
}

All the other public variables are showing up, but the rayRange is not showing up, even if I put [SerializeField]. Can anyone tell what I’m doing wrong? Haha.

Thanks in advance.

Do you have any compile errors in your project?

1 Like

No, the list is clear

Did you save your code?

1 Like

Yeah,I even tried exiting Unity, restarting Visual Studio, reattaching the script.
This is what it looks like in the inspector,

That image shows a script called EnemyAttack, but your code is called BitingMold. Did you attach the correct script?

1 Like

Haha! I feel like an idiot. I changed the name previously to EnemyAttack, and it seems the script duplicated?? So the one that I was editing was not attached, even though I opened it up through the inspector! It got confused because of the other script with the same name

I fixed it, thank you!

1 Like