Hello,
I try to make my game iOS-compatible so I added #pragma strict
at the beginning of every script. That was going well, then I got an error I can’t fix.
First, this is working well with pragma strict :
var pawnToDestroyScript : PawnScript ;
pawnToDestroyScript = pawnToDestroy.GetComponent("PawnScript");
pawnToDestroyScript.pawnBaseReset();
Then I try to get quite the same logic with this one, and here comes the problem :
static function NextStage(stageNumber : int) {
var stageToGo : String = "Level" + stageNumber;
var tempPlateauObj : GameObject = GameObject.Find("Plateau");
stageToGoScript : stageToGo = tempPlateauObj.GetComponent(stageToGo) as stageToGo;
stageToGoScript.InitLevel();
}
The error is “the name stageToGo does not denote a valid type (‘not found’)”
I tried with this form (as seen on other threads) :
var stageToGoScript : stageToGo = tempPlateauObj.GetComponent.<stageToGo>() ;
→ not working
I tried to add “as stageToGo
” at the end as seen on other threads…
→ not working
Then I tried to change the type of stageToGo :
var stageToGo : String
→ not working (it was, without pragma strict)
or
var stageToGo : MonoBehaviour
→ not working
or
var stageToGo : Component
→ not working, nor with GameObject, nor with GameObject.Component nor with Component.stageToGo (I know I’m a noob ;))
→ What is the type of my stageToGo variable ?
It seems I cannot write " var stageToGoScript : stageToGo " since “stageToGo” is not the actual name of the component. The actual name of this component is formed of a string (“Level”) and an integer (stageNumber). (Then I have several script attached to “Plateau”, called “Level1”, another one called “Level2”, etc.)
So what can I do to respect pragma strict with this one ?
I’m new to programming, and I’m sure there are several ways to solve my probleme: I’m eager to learn, so any tip will be welcome