для персонажа нашёл код и получил "Ошибка CS0229 Неоднозначность между "PlayerBehaviour.xVelocity" строки 106/109". как это решить, и можно

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBehaviour : MonoBehaviour
{
    /**
    ** Ускорение игрока
    **/
    [Header("Player velocity")]
    // Ось Ox
    public int xVelocity = 5;
    // Ось Oy
    public int yVelocity = 8;
    private int _xVelocity;

    // Физическое поведение (тело) объекта
    private readonly Rigidbody2D RigidBody;

    public PlayerBehaviour()
    {
    }

    public Rigidbody2D RigidBody { get; private set; }
    public Rigidbody2D RigidBody1
    {
        get
        {
            return this.RigidBody1;
        }

        set => this.RigidBody1 = value;
    }

    public Rigidbody2D RigidBody2
    {
        get
        {
            return this.RigidBody2;
        }
    }

    public Rigidbody2D RigidBody3
    {
        get
        {
            return this.RigidBody3;
        }
    }

    public override bool Equals(object other)
    {
        return base.Equals(other);
    }

    public override int GetHashCode()
    {
        return base.GetHashCode();
    }

    public override string ToString()
    {
        return base.ToString();
    }

    private void Start() =>
        // Получаем доступ к Rigidbody2D объекта Player
        RigidBody1 = gameObject.GetComponent<Rigidbody2D>();

    private void Update()
    {
        UpdatePlayerPosition();
    }

    // Обновляем местоположение игрока
    private void UpdatePlayerPosition()
    {
        // Получаем значение ввода горизонтального перемещение
        float moveInput = Input.GetAxis("Horizontal");
        // Получаем значение ввода прыжка
        float jumpInput = Input.GetAxis("Jump");

        // Значения xVelocity, yVelocity можно задать через инспектор
        NewMethod(moveInput);

        if (jumpInput > 0)
        { //Тип прыгает
            RigidBody1.velocity = new Vector2(RigidBody1.velocity.x, yVelocity);
        }
    }

    private void NewMethod(float moveInput)
    {
        if (moveInput < 0)
        { // Движ влево
            NewMethod2();
        }
        else if (moveInput > 0)
        { // Движ вправо
            NewMethod1();
        }
    }

    private void NewMethod2()
    {
        RigidBody1.velocity = new Vector2(-xVelocity, RigidBody1.velocity.y);
    }

    private void NewMethod1() => RigidBody1.velocity = new Vector2(xVelocity, RigidBody1.velocity.y);
}

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