mirror of
				https://github.com/DerTyp7/harvestdale-unity.git
				synced 2025-10-30 21:17:09 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			753 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			753 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| public class PlayerMovement : MonoBehaviour
 | |
| {
 | |
|   public float moveSpeed = 5f;
 | |
|   private Rigidbody2D rb;
 | |
|   private Animator animator;
 | |
|   private Vector2 movement;
 | |
| 
 | |
|   void Start()
 | |
|   {
 | |
|     rb = GetComponent<Rigidbody2D>();
 | |
|     animator = GetComponent<Animator>();
 | |
|   }
 | |
| 
 | |
|   void Update()
 | |
|   {
 | |
|     movement.x = Input.GetAxisRaw("Horizontal");
 | |
|     movement.y = Input.GetAxisRaw("Vertical");
 | |
| 
 | |
|     animator.SetFloat("Horizontal", movement.x);
 | |
|     animator.SetFloat("Vertical", movement.y);
 | |
|     animator.SetFloat("Speed", movement.sqrMagnitude);
 | |
| 
 | |
|   }
 | |
| 
 | |
|   void FixedUpdate()
 | |
|   {
 | |
|     movement.Normalize();
 | |
|     rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
 | |
|   }
 | |
| } | 
