When I try to move the Prefabs from my Hierarchy to the Project I get this error

You are trying to save a Prefab that contains the script Mover which does not derive from Monobehavior.

I Googled and used my intuition and it seems that it is because my console has errors? I checked to see that MonoBehaviour was there, it’s probably the same bracket issues?

BTW, I do Google before I write these. It’s just that I am at that stage of learning in which I’m trying to consolidate all my knowledge.

Your mover script contains errors, most likely…
Paste in a screen shot of the error (I really want to see the details, which you can get by clicking on the error) as well as your Mover.cs script.

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

namespace RPG.Movement {


   
public class Mover : MonoBehaviour
{
    [SerializeField] Transform target;

       NavMeshAgent navMeshAgent;

        private void Start()
        {
            navMeshAgent = GetComponent<NavMeshAgent>();
        }


        private void Update()
    {
        UpdateAnimator();
    }

        public void StartMoveAction(Vector3 destination)

        {
            GetComponent<Fighter>().Cancel();
            MoveTo(destination);
        }


    public void MoveTo(Vector3 destination)
    {
        GetComponent<NavMeshAgent>().destination = destination;
            navMeshAgent.isStopped = false;
        }

    public void Stop()
        {

            navMeshAgent.isStopped = true;
        }



    private void UpdateAnimator()
    {
        Vector3 velocity = GetComponent<NavMeshAgent>().velocity;
        Vector3 localVelocity = transform.InverseTransformDirection(velocity);
        float speed  = localVelocity.z;
        GetComponent<Animator>().SetFloat("forwardSpeed", speed);
    }
}}

Check your error messages, it’s telling ou that there is an issue with the Fighter script. This is preventing compilations.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms