Script cannot be found? The type or namespace name `Script' could not be found. Are you missing a using directive or an assembly reference?
Hi guys, working on some Simple SPaceship AI here, and trying to activate another script from my C#. The type or namespace name `WaypointMover' could not be found. Are you missing a using directive or an assembly reference?
using UnityEngine;
using System.Collections;
public class EXTFighetrAI : MonoBehaviour {
//Fighter Controll:
public float TurnSpeed = 12f;
public float ShipSpeed = 12f;
public Transform Target;
public Transform Waypoint;
public GameObject MachGunBulletsEXT;
public float fireRate = 0.00F;
private float nextFire = 0.1F;
public float FireSpeed = 3F;
// Gun Controll:
//----------------------------------------------------------------------------------------
// Use this for initialization
void Start () {
}
//----------------------------------------------------------------------------------------
// Update is called once per frame
void Update () {
// check distance of User from the Fighter
float dist = Vector3.Distance(Target.position, transform.position);
print("Distance to other: " + dist);
//----------------------------------------------------------------------------------------
if (dist < 200) {
transform.LookAt(Target);
//Dissable patrol script.
}
//----------------------------------------------------------------------------------------
if (dist < 30) {
// Fire Main Guns.
nextFire = Time.time + fireRate * FireSpeed;
GameObject clone = Instantiate(MachGunBulletsEXT, transform.position, transform.rotation) as GameObject;
}
//----------------------------------------------------------------------------------------
if (dist > 200) {
// Enable Patroll Script.
transform.LookAt(Waypoint);
}
}
///
void OnTriggerEnter(Collider other) {
if (other.CompareTag("Waypoint"))
this.gameObject.GetComponent<WaypointMover> ().enabled = true;
}
}
Answer by Fredex8 · Mar 07, 2016 at 12:58 PM
That code should work fine. I know it sounds stupid but have you double checked that WaypointMover is actually a public class assigned to this gameobject, no spelling mistakes etc? I've only seen that error when the class genuinely doesn't exist because I've mistyped something.
It may be worth removing the space between the >
and (
and adding some braces to the if statement to neaten things up, also you might not need the this.gameObject
but none of that should cause this error. You might want to cache the script reference on start though so it isn't getting it every time it collides:
public WaypointMover waypointMover;
void Start () {
waypointMover = gameObject.GetComponent<WaypointMover>();
}
...
void OnTriggerEnter(Collider other) {
if (other.CompareTag("Waypoint"))
{
waypointMover.enabled = true;
}
}
Assets/Scripts/AI/EXTFighetrAI.cs(12,16): error CS0246: The type or namespace name `Waypoint$$anonymous$$over' could not be found. Are you missing a using directive or an assembly reference?
Your answer
![](https://koobas.hobune.stream/wayback/20220612070920im_/https://answers.unity.com/themes/thub/images/avi.jpg)