Если ошибка очевидна, то не судить строго, я только начинаю этим заниматься.
код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero : MonoBehaviour
{
[SerializeField] private float speed = 3f;
[SerializeField] private int lives = 5;
[SerializeField] private float jumpForce = 15f;
private Rigidbody2D rb;
private SpriteRenderer sprite;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
sprite = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if (Input.GetButton("Horizontal"))
Run();
if (Input.GetButtonDown("Jump"))
Jump();
}
private void Run()
{
Vector3 dir = transform.right * Input.GetAxis("Horizontal");
transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
sprite.flipX = dir.x < 0.0f;
}
private void Jump()
{
rb.AddFors(transform.up * jumpForce, ForceMode2D.Impulse);
}
}
ошибка:
Assets\scripts\Hero.cs(42,12): error CS1061: 'Rigidbody2D' does not contain a definition for 'AddFors' and no accessible extension method 'AddFors' accepting a first argument of type 'Rigidbody2D' could be found (are you missing a using directive or an assembly reference?)