- Home /
I cant reference this class in another script
I have this class in one of my scripts
public class Connection
{
public Point target1;
public Point target2;
public ConnectionType cType;
}
and in another script, this throws back an error where it cant reference "Connection"
public List<Connection> ConnectedPoints = new List<Connection>();
Answer by Tom4nt · Jan 08 at 01:22 AM
You have to make sure both the Connection class and the class where the list is are in the same namespace, or, if not, that you are referencing the namespace.
Also, if you put a script in a folder called "Editor", Unity compiles it in another assembly. Make sure both or neither are in that folder.
Answer by KloverGames · Jan 08 at 04:17 AM
So here is the Connection class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Connection
{
//I don't know what library you're using :(
public Vector3 target1;
public Vector3 target2;
public string cType;
}
So here is the script that's referencing Connection:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReferenceConnection
{
List<Connection> getConnection = new List<Connection>();
}
So here is a picture of the editor where I keep my scripts:
Your answer
Follow this Question
Related Questions
Abstracting class vars, accessing vars by variable 0 Answers
How to reassign a variable's class 1 Answer
class inheriting Vector3 without using monobehavior? 1 Answer
C# Class and Array 1 Answer
Cleaning Up Classes In Lists 1 Answer