- Home /
How would i make it transform player.position =target.position?
 #pragma strict
 
 var buttonInRange;
 var buttonActivated;
 var doorSound : AudioClip;
 var target : Transform;
 
 
 function OnTriggerEnter(c : Collider)
 {
    buttonInRange =true;
 
 }
 function OnTriggerExit (c : Collider)
 {
 buttonInRange = false;
 }
 function Update () 
 {
 if(buttonInRange == true)
 {
  if(Input.GetKeyDown("e")) 
  {
         player.transform.position = target.position;
     }
 }
 }
 
Answer by Kishotta · Jul 01, 2017 at 04:20 AM
I'm not sure I understand your question. You already have code that will set this object's position to the target's position when the 'e' key is pressed.
I understand that, but I have no idea what you're having a problem with. Your code clearly already moves the gameobject the above script is attached to to a target Transform's position. You really need to be sure to ask a thorough question that describes what, specifically, your code is doing or not doing that is different from what you would expect.
We can't read your $$anonymous$$d.
Answer by tanoshimi · Jul 01, 2017 at 06:51 AM
The thing you're missing is that you never assign a value to "player". So make it a public variable at the top of your script and then drag a reference to the player into that slot in the inspector:
 var player : GameObject;
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                