- Home /
 
               Question by 
               pipercubjl · Sep 16, 2012 at 03:48 PM · 
                javascripttransform.positioncheckpoint  
              
 
              Checkpoint Scripting Help
I have one script on a sphere with a sphere trigger collider. This is the script:
 function OnTriggerEnter (other : Collider) {
 
 PlayerCheckpointScript.checkpoint = transform.position;
 Destroy(gameObject);
 
 }
Then I have this script on the First Person Controller:
 static var checkpoint : Vector3;
 
 function Update () {
 
 }
 
 static function death() {
 
 transform.position = checkpoint;
 
 }
I am getting this error:
 An instance of type 'UnityEngine.Component' is required to access non static member 'transform'
Please help.
               Comment
              
 
               
              Answer by whydoidoit · Sep 16, 2012 at 03:56 PM
It is due to the fact. That the death function is static and doesn't know which player script to reference. I presume that there is only one so you should probably make a static variable on the script with the death function that you set to this during awake an use that to access the transform.
Eg:
 static var current  : NameOfThisScript;
 
 void Awake() {
     current = this;
 }
 
 static void Death() {
     current.transform.position = checkpoint;
 } 
Or you could then make Death non-static and call it through current.
 NameOfYourScript.current.Death();
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                