Use AddComponent() to create components. A component needs to be attached to a GameObject.
using UnityEngine;
class Foo : MonoBehaviour { }
class Camera : MonoBehaviour
{
public void Update() {
Foo foo = new Foo();
}
}Use gameObject.AddComponent():
using UnityEngine;
class Foo : MonoBehaviour { }
class Camera : MonoBehaviour
{
public void Update() {
Foo foo = gameObject.AddComponent<Foo>();
}
}A code fix is offered for this diagnostic to automatically apply this change.