- Home /
Unexpected token ) when dealing with getcomponent
I am using my progress bar thing, but it gives me an error. If anyone knows why, please help me out!
#pragma strict
var spawner = GetComponent();
var barRenderer = spawner.instance; // bar renderer allows to access rendering properties
var bar = barRenderer.GetComponent(); // allows to change bar value
// bar.ValueF = 1.0f; - will fill the bar to maximum value
var maxHealth:float = 1000;
var Health:float = 1000;
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
bar.ValueF = Health/maxHealth;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
Destroy (gameObject);
}
Here is a picture of the errors: http://gyazo.com/562db101fabd75c3c57a1cec0394e2d3
Answer by NoseKills · Jul 01, 2015 at 07:37 PM
Just look at the API docs when you have problems with a function. Each GameObject can have any number of components, (transform, SpriteRenderer, MeshRenderer, any Monobehaviour you wrote yourself) and you are not specifying which component to "get" in GetComponent()...
For some reason I can't put < or > in the question. I had written < EnergyBarSpawnerUGUI >
between the first getcomponent and parentheses
GetComponent(Component)
You need to use the code button 101010. If this doesnt work put spaces around the
Oh yeah those old angle brackets. Also, if you put them in the title of a question, they break the whole page.
Looks like you were trying to use the C# syntax for that method in your JS class