Here is some example C# code for a simple player character movement in a 2D platformer game:
using UnityEngine;
public class PlayerMovement : MonoBehaviour { public float speed = 6f; private Vector3 movement; private Rigidbody playerRigidbody; private int floorMask; private float camRayLength = 100f; void Awake () { floorMask = LayerMask.GetMask ("Floor"); playerRigidbody = GetComponent <Rigidbody> (); } void FixedUpdate () { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); Move (h, v); } void Move (float h, float v) { movement.Set (h, 0f, v); movement = movement.normalized * speed * Time.deltaTime; playerRigidbody.MovePosition (transform.position + movement); } }
0 yorum :
Yorum Gönder