using System.Collections; using System.Collections.Generic; using UnityEngine; public class Mover : MonoBehaviour { public GameObject player; public float leftBoundary; public float rightBoundary; bool movingLeft = false; public float maxESpeed = 10f; Rigidbody2D rb; // Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player"); //rb = GetComponent(); } // Update is called once per frame Vector2 movement; void Update() { movement.x = maxESpeed * Time.deltaTime; movement.y = 0; } //moving player void FixedUpdate() { if(gameObject.transform.position.x > rightBoundary) { movingLeft = true; } else if(gameObject.transform.position.x < leftBoundary) { movingLeft = false; } if(gameObject.transform.position.y <0) { // rb.movePosition.y = 0; } if(movingLeft) { Vector2 moveTo = (Vector2)transform.position - movement; transform.position = moveTo; } else { Vector2 moveTo = (Vector2)transform.position + movement; transform.position = moveTo; } } }