Top.Mail.Ru
Ответы

Scripts\Player.cs(11,35): error CS1519: Invalid token ';' in class, record, struct, or interface member declaration

мой код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

private Rigidbody2D rb;
public float dirX, dirY;
public float speed;
public float Joystick joystick;



void Start()
{
Rb = GetComponent<Rigidbody2D>();
}


void Update()
{
dirX = Joystick.Horizontal * speed;
dirY = Joystick.Vertical * speed;
}


void FixedUpdate()
{
Rb.velocity = new Vector2(dirX, dirY);
}
}

и после сохранения юнити пишет о ошибках которые мне не удается решить
2 ошибки:
Assets\scripts\Player.cs(11,27): error CS1002: ; expected

Assets\scripts\Player.cs(11,35): error CS1519: Invalid token ';' in class, record, struct, or interface member declaration

По дате
По рейтингу
Аватар пользователя
Оракул
8мес
12345678910111213141516171819202122232425262728
 using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
 
public class Player : MonoBehaviour 
{ 
    private Rigidbody2D rb; 
    public float dirX, dirY; 
    public float speed; 
    public Joystick joystick; // Удалено слово 'float' перед 'Joystick' 
 
    void Start() 
    { 
        rb = GetComponent<Rigidbody2D>(); // Изменено 'Rb' на 'rb' 
    } 
 
    void Update() 
    { 
        dirX = joystick.Horizontal * speed; // Изменено 'Joystick' на 'joystick' 
        dirY = joystick.Vertical * speed; // Изменено 'Joystick' на 'joystick' 
    } 
 
    void FixedUpdate() 
    { 
        rb.velocity = new Vector2(dirX, dirY); // Изменено 'Rb' на 'rb' 
    } 
} 
 
Аватар пользователя
Мастер
8мес

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

public class Player : MonoBehaviour
{

private Rigidbody2D rb;
public float dirX, dirY;
public float speed;
// public float Joystick joystick; // Удалена эта строка

public Joystick joystick; // Добавлен объект типа Joystick


void Start()
{
rb = GetComponent<Rigidbody2D>();
}


void Update()
{
dirX = joystick.Horizontal * speed;
dirY = joystick.Vertical * speed;
}


void FixedUpdate()
{
rb.velocity = new Vector2(dirX, dirY);
}
}

Аватар пользователя
Искусственный Интеллект
8мес

public float Joystick joystick;

Что за ересь?