Weird GetComponent error

GetComponent in my script is giving me the following error:

“No appropriate version of ‘UnityEngine.GameObject.GetComponent’ for the argument list ‘(UnityEngine.GameObject)’ was found.”

Can anyone spot the problem? The error info doesn’t really say much.

var Rocket : GameObject;

function Explode() {

var TempComp = Rocket.GetComponent(Rocket); //the line with error
var Damage = TempComp.Damage;

}

Your game object in the script is called Rocket and I suspect you also have a script called Rocket.

Problem is that now the compiler thinks Rocket is the local one, the game object and GetComponent does not take GameObject.

Solution:

Change the variable name for :

var RocketObject : GameObject;

var TempComp = RocketObject.GetComponent(Rocket); //the line with error

Don’t call a variable the same as your class. I.e. Change

var Rocket: GameObject

To

var somethingotherthanrocket: GameObject