Unityengine.component does not contain type : Target (Need some more help!)

My code is to change the target variable of the smoothfollow js script to the newly spawned gameobject in my c# init program. Someone recommended this code? But it seems to hate me?

GameObject objectwithscript;
Component followscript;
objectwithscript = GameObject.Find("Camera");
followscript = objectwithscript.GetComponent("SmoothFollow");
followscript.Target = Localhostplayer.transform;

Roberthu produced a lovely script. But that then also produced errors. The scripts name in the inspector is “Smooth Follow” but the script file name SmoothFollow.js? The error I get is: Type “SmoothFollow” does not contain a defination for ‘Target’ and no extension method? Heeeeelp?

You can do it this way:

SmoothFollow followscript = GameObject.Find("Camera").GetComponent<SmoothFollow>();
followscript.Target = Localhostplayer.transform;

You want to avoid using strings (quotes) in GetComponent() call. When you use a string, the compiler does not know the type at compile time. So the result is of type ‘Component’ rather than the type you really want ‘SmoothFollow’. You could cast the result, but this way is less error prone and efficient. If you have no further use of ‘followscript’ you can cut this down to:

GameObject.Find("Camera").GetComponent<SmoothFollow>().Target = Localhostplayer.transform;