Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

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

Роман Козлов Бебрович Ученик (94), открыт 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.
Дополнен 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);
}
}
1 ответ
Лев Перфилов Просветленный (33991) 1 месяц назад
Ты бы ещё без пробелов код скинул. Вообще ничего не разобрать, скинь по-нормальному.
Роман Козлов БебровичУченик (94) 1 месяц назад
всё
Лев Перфилов Просветленный (33991) Роман Бебрович, У тебя после "GetComponent<Rigidbody>().linearVelocity -= moveDirection;" лишняя фигурная скобка.
Похожие вопросы