i need help i keep getting an error saying "NullReferenceException: Object reference not set to an instance of an object
TestMovement2.MovePlayer () (at Assets/TestMovement2.cs:48)
TestMovement2.FixedUpdate () (at Assets/TestMovement2.cs:33)"
here's the script using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestMovement2 : MonoBehaviour
{
[Header ("Movement")]
public float moveSpeed;
public Transform Orientation;
float horizontalInput;
float verticalInput;
Vector3 moveDirection;
Rigidbody rb;
void start ()
{
rb = GetComponent();
rb.freezeRotation = true;
}
private void Update()
{
MyInput();
}
private void FixedUpdate ()
{
MovePlayer();
}
private void MyInput()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
}
private void MovePlayer()
{
//calculate movement direction
moveDirection = Orientation.forward * verticalInput + Orientation.right * horizontalInput;
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestMovement2 : MonoBehaviour
{
[Header ("Movement")]
public float moveSpeed;
public Transform Orientation;
float horizontalInput;
float verticalInput;
Vector3 moveDirection;
Rigidbody rb;
void start ()
{
rb = GetComponent();
rb.freezeRotation = true;
}
private void Update()
{
MyInput();
}
private void FixedUpdate ()
{
MovePlayer();
}
private void MyInput()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
}
private void MovePlayer()
{
//calculate movement direction
moveDirection = Orientation.forward * verticalInput + Orientation.right * horizontalInput;
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
}
Please help me
↧