As I said I’m just learning and I’m creating a simple platformer game, but I dunno why some errors appeared (I ran the game and it worked fine, but one second later the errors just appeared):
public class PlayerMovement : MonoBehaviour {
private Rigidbody2D rigidB;
private Animator animator;
private SpriteRenderer spriteR;
float speed = 2f;
float xDirection;
private void Start() {
rigidB = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
spriteR = GetComponent<SpriteRenderer>();
}
private void Update() {
xDirection = Input.GetAxisRaw("Horizontal");
rigidB.velocity = new Vector2(xDirection * speed, rigidB.velocity.y);
if(Input.GetButtonDown("Jump")) {
rigidB.velocity = new Vector2(rigidB.velocity.x, 6);
}
UpdateAnimations();
}
private void UpdateAnimations() {
if(Input.GetKey("x")) {
speed += 0.7f;
} else {
speed = 2f;
}
if(speed > 7f) {
speed = 2.5f;
}
if(xDirection > 0f) {
animator.SetBool("running", true);
spriteR.flipX = false;
} else if(xDirection < 0f) {
animator.SetBool("running", true);
spriteR.flipX = true;
} else {
animator.SetBool("running", false);
}
}
}
public class CameraController : MonoBehaviour {
[SerializeField] private Transform player;
private void Update() {
transform.position = new Vector3(player.position.x, player.position.y, transform.position.z);
}
}
This are the only two scripts that I have and the errors are these: