- Home /
distance script not working!!!
i have this script:
var box : Transform;
function Update () {
var dist : float = Vector3.Distance(box.position, transform.position);
if(dist <= 20){
GetComponent("veahcle script 3") enabled = true;
}else{
GetComponent("veahcle script 3") enabled = false;
}
}
it says on the 2 get component lines that i need 2 insert ; at the end... but there r... HELP ME!!!! thanks in advance :)
Beside the period you've forgot, you shouldn't use spaces in class/script names. You won't be able to access them as a class since classnames can't include spaces.
Answer by Bampf · Feb 13, 2011 at 09:10 PM
You appear to be missing a period between the GetComponent call and the "enabled = true".
GetComponent("veahcle script 3").enabled = true;
(Note that there are safer ways to write this, but if the component with the given name is guaranteed to exist then it should work. If you spell it differently here then there will be no component found, and you'll get a runtime error.)
oh, i feel like an idiot :P thanks for your help :)
Your answer
Follow this Question
Related Questions
Checking the distance between an instantiated object and an existing object 1 Answer
Access a GameObject through it's tag, using a string. 1 Answer
'enabled' is not a member of 'Object' 1 Answer
Having some trouble with GetComponent(ScriptName"); Missing Method Exception. 0 Answers
How to have GetComponentWithTag return more than one object? 2 Answers