Must derive from MonoBehaviour or ScriptableObject

Hello everyone. I got this compiler warning which is driving me nuts because it just wont leave.

The class defined in the script file named 'VectorGrid' is not derived from MonoBehaviour or ScriptableObject!

This kind of confuses my because I got more classes that are not derived from any of these.

Edit: This was not the root of my “can not build for IOS” problem. Though it confuses me. I could not build the iOS app cause I didnt read the Vectrosity Documentation (using source code now instead of dll and it works)

Here is the class that causes the error:

public class VectorGrid{

	private float strength;
	private float height;
	private float lineOffset;
	private int lineCount;

	public VectorLine line;
	public VectorLine smallLines;
	
	public VectorGrid () {
		strength = 0.5f;
		height = 0.5f;
		lineOffset = 10f;
		lineCount = 10;
		
		float xOffset = -((lineCount-1) * lineOffset);
		float zOffset = -((lineCount-1) * lineOffset);
		Vector3[] arr = new Vector3[lineCount*4];
		
		// z axis
		for(int i = 0; i < lineCount*2 ; i+=2){
			arr _= new Vector3(i*lineOffset+xOffset, height, zOffset);_

_ arr[i+1] = new Vector3(i*lineOffset+xOffset, height, (lineCount-1)lineOffset2+zOffset);_

  •  }*
    
  •  // x axis*
    

_ for(int i = 0; i < lineCount2 ; i+=2){_
_ arr[i+20] = new Vector3(xOffset, height, i
lineOffset+zOffset);_
_ arr[i+20+1] = new Vector3((lineCount-1)lineOffset2+xOffset, height, i*lineOffset+zOffset);_

  •  }*
    
  •  line = new VectorLine("Line", arr, Color.gray, null, strength);*
    
  • }*

  • public void alignTo(GameObject go){*

  •  GameObject line = GameObject.Find("Vector Line") as GameObject;*
    
  •  if(line == null)*
    
  •  	throw new Exception("VectorGrid: Line not found on scene");*
    
  •  line.transform.parent = go.transform.GetChild(0);*
    
  •  line.transform.position = go.transform.TransformPoint(Vector3.zero);*
    
  •  line.transform.rotation = go.transform.GetChild(0).rotation;*
    
  •  line.transform.Rotate(Vector3.right, 90f);*
    
  • }*
    }
    I appreciate any answer, comment or thought

At the end of your class definition you need to add :

public class VectorGrid : MonoBehavior {
///…
}

or if you don’t want to derive from that, you need to remove anything you’ve declared that uses the MonoBehaviour class.

Ok. I removed the Transform.GetChild(int) method in my AlignTo method and the Warning seems to be gone.

Thanks TonyLi

I was saved by the following advice: “Remove the line “using UnityEditor” and all will be well ;)”

Perhaps you can be too :wink: