Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MoveRightLeft : MonoBehaviour {
- float posX;
- float posY;
- float speed = 0.1f;
- int direction = 1;
- // Use this for initialization
- void Start () {
- posX = transform.position.x;
- posY = transform.position.y;
- }
- // Update is called once per frame
- void Update ()
- {
- transform.position = new Vector3 (posX, posY, 0);
- posX += speed * direction;
- // if (posX > 7f) {
- // direction = -1;
- // } else if (posX < -7f) {
- // direction = 1;
- // }
- //
- if (posX > 7f || posX < -7f) {
- direction *= -1;
- }
- }
Add Comment
Please, Sign In to add comment