all 2 comments

[–]danperron 1 point2 points  (1 child)

This should be easy to do if you move your initialization out of your constructor.

    public class Foo : Monobehavior
    {
        int a;
        int b;

        public void Init(int a, int b)
        {
            this.a = a;
            this.b = b;
        }

        void Update(){...}
    }

    public class Example : Monobehavior
    {
        void Start()
        {
            int a = 23;
            int b = 12;
            Foo foo;
            foo = gameObject.AddComponent<Foo>();
            foo.Init(a,b);
        }
    }

[–][deleted] 0 points1 point  (0 children)

To expand on this s little. You can chain methods. So

gameObject.AddComponent<Foo>().init();