I have 2 scripts; Characterdamage2.js & spawn.js
I want to get a variable in CharacterDamage2 and use it in spawn.
Pretty much I want the variable “hitPoints” in CharacterDamage2 to +=10 with every wave in the spawn script but I don’t know what I’m doing wrong.
var otherScript: OtherScript = GetComponent(OtherScript);
otherScript.DoSomething();
And you are trying to do it this way:
var OtherScript: OtherScript = GetComponent(OtherScript);
OtherScript.DoSomething();
It’s similar, but not the same. The variable in the example uses the variable “otherScript”, and a script named “OtherScript”. Your code should work fine if you use a different name for your variable, like this:
var characterDamage2: CharacterDamage2 = hitpoints(CharacterDamage2);
characterDamage2.hitPoints += 1.0;
But I would use the solution of syclamoth, just to be sure not do any typos later.