using System.Collections; using System.Collections.Generic; using UnityEngine; public class Goomba : MonoBehaviour{ public float speed; public float maxSpeed; Rigidbody2D rb2d; bool canMove; // Start is called before the first frame update void Start(){ rb2d = GetComponent(); } void OnBecameVisible(){ canMove = true; } // Update is called once per frame void Update(){ rb2d.AddForce(Vector2.left * speed); float limitedSpeed = Mathf.Clamp(rb2d.velocity.x, -maxSpeed, maxSpeed); rb2d.velocity = new Vector2(limitedSpeed, rb2d.velocity.y); } }