- Home /
Dont know what im doing wrong?(Error included) (Javascipt)
Error:Assets/die.js(8,30): BCE0005: Unknown identifier: 'Chase'.
#pragma strict
function Update () {
}
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Weapon") {
GetComponent(Chase).enabled = false;
GetComponent.<Animation>().Play();
}
}
You're mixing JS and C#. I just replied to your other question, in full.
He doesn't really mix UnityScript and C# here. This is all valid UnityScript. However the error clearly said that there is nothing with the name "Chase". So he most likely has a typo (maybe different casing) or he doesn't know what he actually want or what he's doing.
I believe the point after GetComponent doesn't work. $$anonymous$$y JavaScript isn't what it was, but I believed the typed version of GetComponent was C# only.
get component the way he stated it requires a string input ... he simply missed the quotes. it should be:
GetComponent("Chase").enabled = false;
or this would work too if you don't need a string lookup.
GetComponent.<Chase>().enabled=false;
i havent written unity script in awhile so i might be wrong but doesn't unity script need var infront of freshly declaired variables ???
function OnTriggerEnter (var col : Collider) {
No, that's wrong. The code is perfectly fine. This line in UnityScript:
GetComponent(Chase);
Is equal to this in C#
((Chase)GetComponent(typeof(Chase)))
So the first example is how you should do it in UnityScript.
The error simply states that there is no class with the name Chase within the current set of namespaces. So neither in the global namespace nor in the currently imported namespaces is any class with the name "Chase".
So he either misspelled the actual class / script name (Note: case sensitive!) or he's missing that class somehow.
Also even if the class existed, this wouldn't work with pragma strict:
GetComponent("Chase").enabled = false
Because the string version returns the base type "Component". Components do not have an enabled property. When using pragma strict everything is strongly typed. Your line would only work with dynamic typing support (i.e. no pragma strict). However that is much slower and isn't recommended
ps: No, "var" is only needed when you declare member variables or local variables inside methods. Arguments are always local variables. It wouldn't make much sense to require the "var" keyword here.
Your answer
Follow this Question
Related Questions
Error while creating an object 0 Answers
Trying to setbool of animator from another object c# 1 Answer
How do I make my projectile deal damage to a target it hit. 1 Answer
Activate/Deactivate Scripts form another Script 2 Answers
"Only assignment, call, increment, decrement and new object expressions can be used as statements" 1 Answer