-
-
Save unity3dcollege/eba946b6fd75bbcbe81d05b04da778c1 to your computer and use it in GitHub Desktop.
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class PlayerMovement : MonoBehaviour | |
| { | |
| private CharacterController characterController; | |
| private Animator animator; | |
| [SerializeField] | |
| private float moveSpeed = 100; | |
| [SerializeField] | |
| private float turnSpeed = 5f; | |
| private void Awake() | |
| { | |
| characterController = GetComponent<CharacterController>(); | |
| animator = GetComponentInChildren<Animator>(); | |
| } | |
| private void Update() | |
| { | |
| var horizontal = Input.GetAxis("Horizontal"); | |
| var vertical = Input.GetAxis("Vertical"); | |
| var movement = new Vector3(horizontal, 0, vertical); | |
| characterController.SimpleMove(movement * Time.deltaTime * moveSpeed); | |
| animator.SetFloat("Speed", movement.magnitude); | |
| if (movement.magnitude > 0) | |
| { | |
| Quaternion newDirection = Quaternion.LookRotation(movement); | |
| transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed); | |
| } | |
| } | |
| } |
Nice
very instructive script but if anyone doesn't know C# hewon't understand anything and can't adapt the script to his game or whatever he's doing.
no they will, just use bolt or visual scripting
ZombieRun2D
ZombieRun2D
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = new Vector3(x, 0, z);
transform.Translate(move * speed * Time.deltaTime);
}
}using UnityEngine;
public class MoneySystem : MonoBehaviour
{
public int money = 1000;
public void AddMoney(int amount)
{
money += amount;
Debug.Log("Баланс: $" + money);
}
public void RemoveMoney(int amount)
{
money -= amount;
Debug.Log("Баланс: $" + money);
}
}using UnityEngine;
public class Job : MonoBehaviour
{
public MoneySystem moneySystem;
void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
moneySystem.AddMoney(500);
Debug.Log("Ты получил зарплату!");
}
}
}using UnityEngine;
public class CarController : MonoBehaviour
{
public float speed = 10f;
public float turnSpeed = 50f;
void Update()
{
float move = Input.GetAxis("Vertical") * speed * Time.deltaTime;
float turn = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
transform.Translate(0, 0, move);
transform.Rotate(0, turn, 0);
}
}
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 5.0f;
void Update()
{
// কীবোর্ডের ইনপুট নেওয়া (W, A, S, D)
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
// মুভমেন্ট ভেক্টর তৈরি করা
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
// ক্যারেক্টারকে মুভ করানো
transform.Translate(movement * speed * Time.deltaTime);
}
}
50
চ
50

{
rb = GetComponent<Rigidbody>();
// यह सुनिश्चित करता है कि प्लेयर का कैरेक्टर लुढ़के नहीं
rb.freezeRotation = true;
}
void Update()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
movementInput = new Vector3(moveX, 0f, moveZ).normalized;
}
void FixedUpdate()
{
float currentSpeed = moveSpeed;
if (Input.GetKey(KeyCode.LeftShift))
{
currentSpeed *= sprintMultiplier;
}
Vector3 moveVelocity = movementInput * currentSpeed;
rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
}
}
)
very instructive script but if anyone doesn't know C# hewon't understand anything and can't adapt the script to his game or whatever he's doing.