How to get a Script Component in C#

Hello,

I am trying to call a function in another objects script in C#. I have done it before in Javascript, but needed to convert over to C# for a few reasons.

How I did it before was: Javascript

TempChunk = Instantiate(chunksL[0] , Vector3 (0, 30, 0), Quaternion(0,0,0,0)); 
TempChunk.GetComponent(ChunkScript).Spawn(0, 30, 30, 30, "None", "Up", false, 0, IndexTracker,"L"); 

I have tried things I have seen on the forums and by searching google, but I must be missing something.

Here it is now:

TempChunk = Instantiate(chunksG[2]) as GameObject; 
TempChunk.GetComponent("ChunkScript").Spawn(XLocation, YLocation, 30, 30, ExitDir, EntranceDir, IndexTracker, tempchar); 

I keep getting `UnityEngine.Component` does not contain a definition for `Spawn`.

Does anyone know how I could fix it?

TempChunk.GetComponent(ChunkScript).Spawn(0, 30, 30, 30, "None", "Up", false, 0, IndexTracker,"L");

should be

((ChunkScript)TempChunk.GetComponent(typeof(ChunkScript))).Spawn(0, 30, 30, 30, "None", "Up", false, 0, IndexTracker,"L");

Otherwise, Unity gets confused as to what you are referencing.

You were missing a typecast, and a typeof specifier.