AddComponent doesnt work anymore with 3.0

Hello,

In unity 2.6 I was using:

private var mysqlconnection : Mysqlconn;    
mysqlconnection = gameObject.AddComponent(Mysqlconn);

This was working very fine (I was adding a MysqlConnection to my script).

Now with Unity 3.0 I get error: Cannot convert 'UnityEngine.Component' to 'Mysqlconn'.

When I use "new" command. Unity tells me to use AddComponent. When I use AddComponent I get the error above.

Please tell me how to fix that, thanks.

1 Answer

1

Add in

#pragma downcast

at the top of your script, or use the generic version of AddComponent,

AddComponent.<Mysqlconn>();

Thanks I used generic Version. But now I get the warning: "Missing Mono Script"