M
M
MegaTochka2021-08-15 17:53:06
C++ / C#
MegaTochka, 2021-08-15 17:53:06

Unity 2d c# script not working, what should I do?

I watched a video in which they make the movement of the character (without animation). He made this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed;
  public float jumpForce;
  private float moveInput;
  
  private Rigidbody2D rb;
  
  private void Start() 
  {
    rb = GetComponent<Rigidbody2D>();
  }
  private void FixUpdate()
  {
    moveInput = Input.GetAxis("Horizontal");
    rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
  }
}

But, when I inserted the script into the player, speed and jumpForce were not shown.
Help, please, I will be very grateful!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question