- Home /
The question is answered, right answer was accepted
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;
}
Answer by fafase · May 24, 2014 at 12:51 PM
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
Answer by tanoshimi · May 24, 2014 at 12:54 PM
Don't call a variable the same as your class. I.e. Change
var Rocket: GameObject
To
var somethingotherthanrocket: GameObject
Follow this Question
Related Questions
error CS0118: `New_Career.Fame' is a `field' but a `type' was expected 1 Answer
GetComponent of ALL clones? 2 Answers
GameObject.getComponent problem 2 Answers
Disabling A Script on a GameObject From a Different Script 2 Answers
What is the difference between GameObject.GetComponent and Component.GetComponent? 1 Answer