You may be having collisions with the ground or other objects that don’t have the script BaseStats. The easiest way to avoid this is to check if the object hit has a BaseStats script:
function OnCollisionEnter(collision:Collision)
{
var baseStScript: BaseStats = collision.gameObject.GetComponent(BaseStats);
if (baseStScript){
var optype1 = baseStScript.type1;
var optype2 = baseStScript.type2;
...
}
}
Which line is 36? The last one? In the last line you have shooter.level, which doesn't seem to make much sense: from the other lines, shooter seems to be a Transform of GameObject, and none of them have a level property. Could it be a BaseStats variable? By the way, it would be better to save at the beginning a reference to the shooter BaseStats script, like we did with the variable baseStScript: <pre> var shooterScript: BaseStats = shooter.GetComponent(BaseStats); var STAB = shooterScript.type1; var STAB2 = shooterScript.type2; ... </pre>
Which line is 36? The last one? In the last line you have shooter.level, which doesn't seem to make much sense: from the other lines, shooter seems to be a Transform of GameObject, and none of them have a level property. Could it be a BaseStats variable? By the way, it would be better to save at the beginning a reference to the shooter BaseStats script, like we did with the variable baseStScript: <pre> var shooterScript: BaseStats = shooter.GetComponent(BaseStats); var STAB = shooterScript.type1; var STAB2 = shooterScript.type2; ... </pre>
– aldonaletto