trying to keep a game object within the screen left and right bounds in unity3d
问题 I have this code bellow for my gameobject : private float screenx; Vector3 playerPosScreen; void Start () { screenx=Camera.main.pixelWidth-renderer.bounds.size.x ; } void update(){ playerPosScreen = Camera.main.WorldToScreenPoint(transform.position); if (playerPosScreen.x >= screenx) { //playerPosScreen.x=screenx; transform.position=new Vector3 (screenx, transform.position.y,transform.position.z); } //txt.text = playerPosScreen.x.ToString(); else if(playerPosScreen.x<=renderer.bounds.size.x){