1

Good evening, currently finishing up an assignment that is almost due and I can't seem to understand as to why this code isn't being assigned. An error that Unity keeps showing me is that the script has to be derived from MonoBehaviour. I have looked up tutorials and threads and I still can't seem to find what is my issue. Below is a copy of my code currently. Assistance is greatly appreciated!!

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

public class Track01Track : MonoBehaviour {

    public GameObject TheMarker;
    public GameObject Mark01;
    public GameObject Mark02;
    public GameObject Mark03;
    public GameObject Mark04;
    public GameObject Mark05;
    public GameObject Mark06;
    public GameObject Mark07;
    public GameObject Mark08;
    public GameObject Mark09;
    public GameObject Mark10;
    public GameObject Mark11;
    public GameObject Mark12;
    public GameObject Mark13;
    public GameObject Mark14;
    public GameObject Mark15;
    public GameObject Mark16;
    public GameObject Mark17;
    public GameObject Mark18;
    public GameObject Mark19;
    public GameObject Mark20;
    public GameObject Mark21;
    public GameObject Mark22;
    public GameObject MarkTracker;

   void Start ()
    {

    }

    void Update () {

        if (MarkTracker == 0)
        {
            TheMarker.transform.position = Mark01.transform.position;
        }
        if (MarkTracker == 1)
        {
            TheMarker.transform.position = Mark02.transform.position;
        }
        if (MarkTracker == 2)
        {
            TheMarker.transform.position = Mark03.transform.position;
        }
        if (MarkTracker == 3)
        {
            TheMarker.transform.position = Mark04.transform.position;
        }
        if (MarkTracker == 4)
        {
            TheMarker.transform.position = Mark05.transform.position;
        }
        if (MarkTracker == 5)
        {
            TheMarker.transform.position = Mark06.transform.position;
        }
        if (MarkTracker == 6)
        {
            TheMarker.transform.position = Mark07.transform.position;
        }
        if (MarkTracker == 7)
        {
            TheMarker.transform.position = Mark08.transform.position;
        }
        if (MarkTracker == 8)
        {
            TheMarker.transform.position = Mark09.transform.position;
        }
        if (MarkTracker == 9)
        {
            TheMarker.transform.position = Mark10.transform.position;
        }
        if (MarkTracker == 10)
        {
            TheMarker.transform.position = Mark11.transform.position;
        }
        if (MarkTracker == 11)
        {
            TheMarker.transform.position = Mark12.transform.position;
        }
        if (MarkTracker == 12)
        {
            TheMarker.transform.position = Mark13.transform.position;
        }
        if (MarkTracker == 13)
        {
            TheMarker.transform.position = Mark14.transform.position;
        }
        if (MarkTracker == 14)
        {
            TheMarker.transform.position = Mark15.transform.position;
        }
        if (MarkTracker == 15)
        {
            TheMarker.transform.position = Mark16.transform.position;
        }
        if (MarkTracker == 16)
        {
            TheMarker.transform.position = Mark17.transform.position;
        }
        if (MarkTracker == 17)
        {
            TheMarker.transform.position = Mark18.transform.position;
        }
        if (MarkTracker == 18)
        {
            TheMarker.transform.position = Mark19.transform.position;
        }
        if (MarkTracker == 19)
        {
            TheMarker.transform.position = Mark20.transform.position;
        }
        if (MarkTracker == 20)
        {
            TheMarker.transform.position = Mark21.transform.position;
        }
        if (MarkTracker == 21)
        {
            TheMarker.transform.position = Mark22.transform.position;
        }
    }

    IEnumerator OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.tag == "Track01")
        {
            this.GetComponent<BoxCollider>().enabled = false;
            MarkTracker += 1;
            if (MarkTracker == 22)
            {
                MarkTracker = 0;
            }
            yield return new WaitForSeconds(1);
            this.GetComponent<BoxCollider>().enabled = true;
        }
    }
}

This is the error:

Can't add script behaviour CallbackExecutor. The script needs to derive from MonoBehaviour.

Screen shot of error message

SOS
  • 6,430
  • 2
  • 11
  • 29
  • 1
    Can you tell us what the actual problem is? Is the question title an error you're getting? Or what? – ProgrammingLlama Sep 10 '18 at 02:18
  • Apologies, the text that unity shows me is; "Can't add script behaviour CallbackExecutor. The script needs to derive from MonoBehaviour". I have checked to see I have been putting in the correct information and I don't believe i'm doing anything wrong. – Mario Garcia Sep 10 '18 at 02:21
  • Unless I'm mistaken (I don't have experience with Unity), the script you've shown above is `Track01Track`, not `CallbackExecutor` - is that correct? – ProgrammingLlama Sep 10 '18 at 02:22
  • Where is the CallbackExecutor script? – Retired Ninja Sep 10 '18 at 02:22
  • That is correct, and I am unsure of what that is – Mario Garcia Sep 10 '18 at 02:23
  • Select the script where it is and post a screenshot of the location where you placed the script. Also show a screenshot of the error – Programmer Sep 10 '18 at 02:35
  • You can't compare MarkTracker to an integer value, that is the problem. – Ron Beyer Sep 10 '18 at 03:02
  • As Ron Beyer mentioned, the problem here is that your script has errors in it. You can't compare MarkTracker to an int. Is there a property of the MarkTracker you meant to compare it to instead? We are referring to the if statements in your Update() function. – Alex Myers Sep 10 '18 at 03:18
  • With your screenshot, there is an error in your script. If your're trying to compare the GameObject name, change `if (MarkTracker == 0)` to `if (MarkTracker.name == "0")`. You have to do this to all of them. – Programmer Sep 10 '18 at 05:55

1 Answers1

2

You should check to see whether your script's 'name' in the Unity Editor corresponds with the name of your class Track01Track.

bolkay
  • 1,881
  • 9
  • 20