Pisałem skrypt do poruszania się postacią w unity ale gdy sprobowalem wejsc w tryb gry wyskoczyl blad jak na zdj.
a tutaj moj skrypt, czy popelnilem gdzies blad? a może trzeba cos zrobic jeszcze w unity?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementSpeed MonoBehaviour
{
[Header(Movement)]
public float moveSpeed = 6f;
public float movementMultiplier = 10f;
float rbDrag = rbDrag;
float horizontalMovement;
float verticalMovement;
Vector3 moveDirection;
Rigidbody rb;
private void Start()
{
rb = GetComponentRigidbody();
rb.freezeRotation = true;
}
private void Update()
{
MyInput();
ControlDrag();
}
void MyInput()
{
horizontalMovement = Input.GetAxisRaw(Horizontal);
verticalMovement = Input.GetAxisRaw(Vertical);
moveDirection = transform.forward verticalMovement + transform.right horizontal Movement;
}
void ControlDrag()
{
rb.drag = rbDrag;
}
private void FixedUpdate{}
{
MovePlayer();
}
void MovePlayer()
{
rb.AddForce(moveDirection.normalized moveSpeed movementMultiplier, ForceMode.Acceleration);
}
}