Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

I have wrote this code following a tutorial by coding in flow for 2d games in unity but came up with many errors seen below. How do I fix these?

$
0
0
Errors: Assets\Scripts\player_movement.cs(37,18): error CS0111: Type 'player_movement' already defines a member called 'UpdateAnimationState' with the same parameter types Assets\Scripts\player_movement.cs(24,19): error CS0111: Type 'player_movement' already defines a member called 'Update' with the same parameter types Assets\Scripts\player_movement.cs(16,19): error CS0111: Type 'player_movement' already defines a member called 'Start' with the same parameter types Assets\Scripts\player_movement.cs(5,14): error CS0101: The namespace '' already contains a definition for 'player_movement'. https://www.youtube.com/watch?v=65E-q0JxYwU&list=PLrnPJCHvNZuCVTz6lvhR81nnaf1a-b67U&index=5 video link of tutorial viewed. using System.Collections; using System.Collections.Generic; using UnityEngine; public class player_movement : MonoBehaviour { private Rigidbody2D rb; private SpriteRenderer sprite; private Animator anim; private float dirX = 0f; [SerializeField] private float moveSpeed = 7f; [SerializeField] private float jumpForce = 12f; private enum MovementState { idle, running, jumping, falling } // Start is called before the first frame update private void Start() { rb = GetComponent(); sprite = GetComponent(); anim = GetComponent(); } // Update is called once per frame private void Update() { dirX = Input.GetAxisRaw("Horizontal"); rb.velocity = new Vector2(dirX * 7f, rb.velocity.y); if (Input.GetButtonDown("Jump")) { rb.velocity = new Vector2(rb.velocity.x, jumpForce); } UpdateAnimationState(); } private void UpdateAnimationState() { MovementState state; if (dirX > 0f) { state = MovementState.running; sprite.flipX = false; } else if (dirX < 0f) { state = MovementState.running; sprite.flipX = true; } else { state = MovementState.idle; } if (rb.velocity.y > .1f) { state = MovementState.jumping; } else if (rb.velocity.y < -.1f) { state = MovementState.falling; } anim.SetInteger("state", (int)state); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>