Hi Im getting 2 nullRefenceExition’s For this bit of code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sliding : MonoBehaviour
{
[Header("Refences")]
public Transform orientation;
public Transform Player;
private Rigidbody rb;
private PlayerMovement3D pm;
[Header("Sliding")]
public float MaxSlideTime;
public float SlideForce;
private float SlideTimer;
public float SlideYScale;
public float StartYScale;
[Header("Input")]
public KeyCode SlideKey = KeyCode.LeftControl;
private float horizontailInput;
private float verticalInput;
private bool sliding;
void start()
{
rb = GetComponent<Rigidbody>();
pm = GetComponent<PlayerMovement3D>();
StartYScale = Player.localScale.y;
}
void Update()
{
horizontailInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
if(Input.GetKeyDown(SlideKey) && (horizontailInput != 0 || verticalInput != 0))
{
StartSlide();
}
if(Input.GetKeyUp(SlideKey) && sliding)
{
StopSlide();
}
}
void FixedUpdate()
{
if(sliding)
{
SlidingMovement();
}
}
private void StartSlide()
{
sliding = true;
Player.localScale = new Vector3(Player.localScale.x, SlideYScale, Player.localScale.z);
rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
SlideTimer = MaxSlideTime;
}
private void SlidingMovement()
{
Vector3 InputDirection = orientation.forward * verticalInput + orientation.right * horizontailInput;
rb.AddForce(InputDirection.normalized * SlideForce, ForceMode.Force);
SlideTimer -= Time.deltaTime;
if(SlideTimer <= 0)
{
StopSlide();
}
}
private void StopSlide()
{
sliding = false;
Player.localScale = new Vector3(Player.localScale.x, StartYScale, Player.localScale.z);
}
}
I know what lines are giving me the errors:
1: rb.AddForce(InputDirection.normalized * SlideForce, ForceMode.Force);
2: rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
I have set all the variables to what they are meant to be.
And the player object as the PlayerMovement3D script on it as well.
I dont know why im getting these errors.
(Sorry Im bad at spelling)