How To Code A Simple Walking Script With C# In Unity

Veröffentlicht am: 21 Januar 2023
auf dem Kanal: ProgrammersProdigy
301
8

Thanks For Watching




Some Parts Will Be Missing Angled Brackets Because YouTube Doesn't Allow It


The First Code Is
--------------------------------------------------------------
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 5f;

private CharacterController characterController;

void Start()
{
characterController = GetComponent CharacterController ();
}
​ void Update()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");

Vector3 movement = new Vector3(horizontal, 0f, vertical);
characterController.Move(movement * moveSpeed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && characterController.isGrounded)
{
characterController.Move(Vector3.up * jumpForce);
}
}
}
---------------------------------------------------------------


The Second Code Is
----------------------------------------------------------------
using UnityEngine;


public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 5f;


Rigidbody rb;


void Start()
{
rb = GetComponent Rigidbody ();
}


void Update()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");


Vector3 movement = new Vector3(moveX, 0f, moveZ);


rb.AddForce(movement * moveSpeed);


if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
}
}
----------------------------------------------------------------------
#tutorial #coding #howto


Auf dieser Seite können Sie das Online-Video How To Code A Simple Walking Script With C# In Unity mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ProgrammersProdigy 21 Januar 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 301 Mal angesehen und es wurde von 8 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!