Want to change the object's scale but show wrong message.

It show

“InternalGetTransform can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.”

This is my Code.

var Wandell : GameObject;
var Albert : GameObject;
var Alvis : GameObject;

var scale : Vector3 = transform.localScale;

function OnTriggerEnter(Player : Collider){

  if(Player.gameObject == Wandell || Albert || Alvis){

   scale.x=1;
   scale.y=1;
   scale.z = 0.1f;
   Wandell.transform.localScale = scale;
   
     if(Wandell.transform.localScale == scale){
   
     yield WaitForSeconds(5);
     scale.z = 1f;   
     Wandell.transform.localScale =  scale;    
   
   }  
}
}

Would anybody know how to fix this problem? Plz,thanks for the help :frowning:

You can’t access ‘transform’ when you initialize instance variables because the game object hasn’t been fully created yet. As the error message says you need to move the initialization logic to the Awake() (or Start) function:

var scale : Vector3;

function Awake() {
    scale = transform.localScale;
}