Answer the question
In order to leave comments, you need to log in
NullReferenceExcepition in Unity2d. What to do?
I'm creating a project in Unity and
I get NullReferenceException: Object reference not set to an instance of an object
MoveScript.FixedUpdate () (at Assets/MoveScript.cs:26
Line 26 is rb.velocity = new Vector2(moveInput * speed, rb.velocity .y
)
;
Here
's
all
the
code
_
_
_
_
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatisGround;
private void Strart()
{
rb = GetComponent();
}
private void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0)
{
Flip();
}
else if(facingRight==true && moveInput < 0)
{
Flip();
}
}
private void Update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatisGround);
if (isGrounded==true && Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = Vector2.up * jumpForce;
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
In the archive, the link is the project itself made in Unity in 2019
https://drive.google.com/file/d/1P_k3xyE3rVBRsY5DD...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question