Ошибка: Assets\Scripts\Character.cs: error CS0443: Syntax error; value expected [ИСПРАВЛЕНО]

Вот тут ошибка:

private void CheckGround(){
    Collider2D[].colliders = Physics2D.OverlapCicleAll(transform.position, 0.3F);

    isGrounded = colliders.Lenghth > 1;
}

Я делаю 2D платформер на Unity и устраняю ошибку с двойным прыжком. Вот весь код персанажа:

using System.Collections.Generic;
using UnityEngine;

public class Character : MonoBehaviour
{
    [SerializeField]
    private int lives = 5;

    [SerializeField]
    private float speed = 5.0F;

    [SerializeField]
    private float jumpForce = 15.0F;

    private bool isGrounded = false;


    new private Rigidbody2D rigidbody;
    private Animator animator;
    private SpriteRenderer sprite;

    private void Awake(){
        rigidbody = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
        sprite = GetComponentInChildren<SpriteRenderer>();
    }

    private void FixedUpdate(){
        CheckGround();
    }

    private void Update(){
        if(Input.GetButton("Horizontal")) Run();
        if(isGrounded && Input.GetButtonDown("Jump")) Jump();
    }

    private void Run(){
        Vector3 direction = transform.right * Input.GetAxis("Horizontal");

        transform.position = Vector3.MoveTowards(transform.position, transform.position + direction, speed * Time.deltaTime);

        sprite.flipX = direction.x < 0.0F;
    }

    private void Jump(){
        rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
    }


    private void CheckGround(){
        Collider2D[].colliders = Physics2D.OverlapCicleAll(transform.position, 0.3F);

        isGrounded = colliders.Lenghth > 1;
    }


}

Ну вот решение:

using System.Collections.Generic;
using UnityEngine;

public class Character : MonoBehaviour
{
    [SerializeField]
    private int lives = 5;

    [SerializeField]
    private float speed = 5.0F;

    [SerializeField]
    private float jumpForce = 15.0F;

    private bool isGrounded = false;


    new private Rigidbody2D rigidbody;
    private Animator animator;
    private SpriteRenderer sprite;

    private void Awake(){
        rigidbody = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
        sprite = GetComponentInChildren<SpriteRenderer>();
    }

    private void FixedUpdate(){
        CheckGround();
    }

    private void Update(){
        if(Input.GetButton("Horizontal")) Run();
        if(isGrounded && Input.GetButtonDown("Jump")) Jump();
    }

    private void Run(){
        Vector3 direction = transform.right * Input.GetAxis("Horizontal");

        transform.position = Vector3.MoveTowards(transform.position, transform.position + direction, speed * Time.deltaTime);

        sprite.flipX = direction.x < 0.0F;
    }

    private void Jump(){
        rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
    }


    private void CheckGround(){
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 0.3F);

        isGrounded = colliders.Length > 1;
    }


}

Ответы (0 шт):