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

Pubblicato il: 21 gennaio 2023
sul canale di: 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


In questa pagina del sito puoi guardare il video online How To Code A Simple Walking Script With C# In Unity della durata di ore minuti seconda in buona qualità , che l'utente ha caricato ProgrammersProdigy 21 gennaio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 301 volte e gli è piaciuto 8 spettatori. Buona visione!