public override void Update() { base.Update(); Room1_FireSlimeScene room = (Room1_FireSlimeScene)GetGameObject().GetComponentInParent(typeof(Room1_FireSlimeScene)); float dx = GetGameObject().transform.position.x; float dy = GetGameObject().transform.position.y; if (dx >= room.transform.position.x + room.max_X || dx <= room.transform.position.x - room.max_X) { GetGameObject().GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetGameObject().GetComponent <Rigidbody2D>().velocity.y); } if (dy >= room.transform.position.y + room.max_Y || dy <= room.transform.position.y - room.max_Y) { GetGameObject().GetComponent <Rigidbody2D>().velocity = new Vector2(GetGameObject().GetComponent <Rigidbody2D>().velocity.x, 0); } }
public void SetRoom(Room1_FireSlimeScene room) { this.room = room; }