- Home /
Question by
PlayCreatively · Aug 04, 2017 at 09:16 PM ·
inheritancestruct
How to make a custom struct like Vector?
I made a struct:
public struct Line
{
public Vector2 start, end;
public Vector2 vectorLine {get{ return end - start;}}
}
But whenever I try to instantiate it like I do with a Vector class
Line touchSwipe = new Line ();
Unity returns this error:
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
Comment
Answer by FlaSh-G · Aug 04, 2017 at 09:46 PM
Your declaration looks okay, as well as the new-line. I am pretty sure you just have a MonoBehaviour class somewhere that happens to also be named "Line".
Right. +1
@PlayCreatively: Are you sure that the error actually comes from that line of code? Have you checked the line numbers?