N
N
nepoluchilos2020-08-09 18:29:30
Unity
nepoluchilos, 2020-08-09 18:29:30

I'm making a 2D platformer on unity using this video https://youtu.be/5vhMXhic2S8 I can't do anything. I write the code in fact exactly exactly. How can I fix this?

I'm making a 2D platformer on unity using this video
https://youtu.be/5vhMXhic2S8
I can't do anything. I write the code in fact exactly exactly, but it does not work. during programming, many components are not highlighted in color.
Here is the script code:

using UnityEngine;

public class controller : MonoBehaviour
 { 
 public float speed;
 public float jumpForce;
 private float moveInput;

 private Rigidbody2D rb;

 private void start()
  { 
 rb = GetComponent();
  } 

 private void FixedUpdate()
  { 
 moveInput = Input.GetAxis("Horizontal");
 rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

  } 

 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
privet_andrei123, 2020-08-10
@privet_andrei123

rb = GetComponent();
I forgot to specify Rigidbody2D ) in <> also don't forget to add the RigidBody2D component to your player
Also don't confuse the Rigidbody2d component with the Rigidbody
Maybe I forgot to set the speed in the inspector panel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question