trying to access a script through a trigger ,please help

I’m trying to access a script through a trigger, using a script that I have used before. The only difference here is that I am trying to access a different script than in the past, so I changed the name in the code which here would be “PathMagic” to get to the PathMagic.cs.

For some reason it won’t work and I get the error:

Assets/ride.cs(10,25): error CS0246: The type or namespace name `PathMagic’ could not be found. Are you missing a using directive or an assembly reference?

This is the code I am using:

using UnityEngine;
using System.Collections;

public class ride : MonoBehaviour {

void OnTriggerEnter(Collider other)
{
	if (other.gameObject.tag == "Player")
	{
		PathMagic PathMagic = gameObject.GetComponent<PathMagic>();
		PathMagic.enabled = true;
	}
}

void OnTriggerExit(Collider other)
{
	if (other.gameObject.tag == "Player")
	{
		PathMagic Pathm=Magic = gameObject.GetComponent<PathMagic>();
		PathMagic.enabled = false;
	}
}

}

Does anyone have any idea what it is that I may be doing wrong? I’m new to Unity and not great with coding yet. Please help.

The issue is the following line:

PathMagic PathMagic = gameObject.GetComponent<PathMagic>();

or even more likely

PathMagic Pathm=Magic = gameObject.GetComponent<PathMagic>();
PathMagic.enabled = false;

The second is more likely because you assign “Pathm” but us"PathMagic".

If that isn’t it then its the first one and I’m guessing…
It appears to me that you are just trying to enable this script. What this needs to be written as is the following:

this.GetComponent<PathMagic>().enabled = true;

That is if you’re trying to in fact enable a component that is present on the trigger object. The issue arises because the name “PathMagic” is spelled the exact same as the type your trying to cast? Maybe? If nothing else you could explicitly cast it:

PathMagic pathMagic = gameObject.GetComponent<PathMagic>() as PathMagic;

or

PathMagic pathMagic = (PathMagic)gameObject.GetComponent<PathMagic>();

The other thing that you might want to check is to make sure the file name “PathMagic.cs” matches the class name exactly.