29 lines
655 B
C#
29 lines
655 B
C#
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<Rigidbody2D>();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|