2014-01-21 121 views
0

我将下面的脚本附加到对象上。 当它碰到左侧或右侧墙壁时,我想重新接近对象,但似乎没有重置位置。Unity3D 2D重置2D物体位置

我在调试窗口中看到'撞墙'。

function OnTriggerEnter2D (hitInfo : Collider2D) 
{ 
var hitSide : boolean = false; 

if (hitInfo.name == "leftWall") 
{ 
    hitSide = true; 
} 
else if (hitInfo.name == "rightWall") 
{ 
    hitSide = true; 
} 

if (hitSide) 
{ 
      Debug.Log("Hit wall"); 
    transform.position.x = Screen.width /2; 
    transform.position.y = Screen.height/2; 
} 
} 

回答