SerializeField field not showing up in inspector?

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


public class ZombieAI : MonoBehaviour

{
    private NavMeshAgent Zombie;
    [SerializeField] private static GameObject Zombro;

    [SerializeField] public static GameObject Player;
    float dist = Vector3.Distance(Player.transform.position, Zombro.transform.position);
  
    [SerializeField] private Animator myAnimationController;
 


    // Start is called before the first frame update
    void Start()
    {
        GetComponent<Animation>();
        Zombie = GetComponent<NavMeshAgent>();
       
    }

    // Update is called once per frame
    void Update()
    {
       
       
        Zombie.SetDestination(Player.transform.position);
        if(dist > 1)
        {
            myAnimationController.SetBool("attack1", true);
        }


    }
}

The fields “Zombro” and “Player” do not show up in the inspector of unity, what am I doing wrong??

Static variables don’t show. Only instance variables.

2 Likes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;


public class ZombieAI : MonoBehaviour

{
    [SerializeField] public GameObject Player;
    [SerializeField] public GameObject Zombro;
    private NavMeshAgent Zombie;

    [SerializeField] private Animator myAnimationController;
 
   
    void Start()
    {
       
        GetComponent<Animation>();
        Zombie = GetComponent<NavMeshAgent>();
       
    }

    // Update is called once per frame
    void Update()
    {
       
       
        Zombie.SetDestination(Player.transform.position);
        if(dist > 1)
        {
            myAnimationController.SetBool("attack1", true);

        }
         if(dist < 1)
        {
            myAnimationController.SetBool("attack1", false);

        }
       


    }
}

Honestly, that was just me messing with different things to see if it would work haha. Here, these don’t show in inspector either

Check your console for errors.
Assets\ZombieAI.cs(31,6): error CS0103: The name 'dist' does not exist in the current context

2 Likes

I was having the same issue but my problem was a little bit different. [SerializedField] variables weren’t showing up because Visual Studio wasn’t connected properly to Unity, so the changes I was making weren’t reflected in Unity properly. Because my script was so small, I didn’t bother putting in the time to figure out why Visual Studio wasn’t connecting to Unity properly, so as a temporary solution, I just refreshed the C# script in Unity and then the Fields showed up.