Top.Mail.Ru
Ответы
Аватар пользователя
Аватар пользователя
Аватар пользователя
Программирование
+1

Помогите в юнити

Помогите пожалуйста только начал делать игры в юнити пишу код как на видео а там ошибка и не понимаю в чем дело
вот код
using UnityEngine; using UnityEngine.SceneManagement; public class Player : MonoBehaviour { [SerializeField] KeyCode keyOne; [SerializeField] KeyCode keyTwo; [SerializeField] Vector3 moveDirection; private void FixedUpdate() { if (Input.GetKey(keyOne)) { GetComponent<Rigidbody>().linearVelocity += moveDirection; } if (Input.GetKey(keyTwo)) { GetComponent<Rigidbody>().linearVelocity -= moveDirection; } } } private void OnTriggerEnter(Collider other) { if(this.CompageTag("Player") && other.CompageTag("Finish")) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); } }
и ошибки
Assets\Player.cs(23,1): error CS0106: The modifier 'private' is not valid for this item
Assets\Player.cs(23,1): error CS8803: Top-level statements must precede namespace and type declarations.

Дополнен
1234567891011121314151617181920212223242526272829
 using UnityEngine;
using UnityEngine.SceneManagement;

public class Player : MonoBehaviour
{
 [SerializeField] KeyCode keyOne;
 [SerializeField] KeyCode keyTwo;
 [SerializeField] Vector3 moveDirection;

    private void FixedUpdate()
 {
    if (Input.GetKey(keyOne))
    {
        GetComponent<Rigidbody>().linearVelocity += moveDirection;
    }
 
if (Input.GetKey(keyTwo))
    {
        GetComponent<Rigidbody>().linearVelocity -= moveDirection;
    }
 }
} 
private void OnTriggerEnter(Collider other)
{
    if(this.CompageTag("Player") && other.CompageTag("Finish"))
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
} 
По дате
По рейтингу
Аватар пользователя
Просветленный
5мес

Ты бы ещё без пробелов код скинул. Вообще ничего не разобрать, скинь по-нормальному.