Syntax for calling a function of another script in C#

I am trying to call a function of a different C# script from within another C# script.

This is what I am trying to do here:

 GameObject.Find("Player").GetComponent("FireScript").PowerUpLaser();

Basically, there’s a function known as “PowerUpLaser” inside FireScript.cs which I am trying to access from inside another script. This works fine in JavaScript but throws me the following error when I tried the same syntax in C#.

error CS0117: `UnityEngine.Component' does not contain a definition for "PowerUpLaser".

Any idea where I am going wrong?

Thanks!

More code less mess :wink:

//Find Gameobject
GameObject go = GameObject.FindGameObjectWithTag("Player");
//Grab the script
FireScript fs = (FireScript)go.GetComponent(typeof(FireScript));
//Call the function
fs.PowerUpLaser();

Thanks a lot! That works just fine :slight_smile:

Another suggestion:

GameObject.FindWithTag("Name").GetComponent<NameOfTheScript>().NameOfTheFunction();