using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
[SerializeField] KeyCode keyOne;
[SerializeField] KeyCode keyTwo;
[SerializeField] KeyCode keyFree;
[SerializeField] KeyCode keyFour;
[SerializeField] Vector3 moveDirection;
private void FixedUpdate()
{
if (Input.GetKey(keyOne))
{
GetComponent<Rigidbody>().velocity += moveDirection;
}
if (Input.GetKey(keyTwo))
{
GetComponent<Rigidbody>().velocity -= moveDirection;
}
if(Input.GetKey(KeyFree))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if(Input.GetKey(KeyFour))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
private void OnTrigger(Collider other)
{
if(this.CompareTag("Player") && other.CompareTag("Finish"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
}
C#
Ребят, конвертируйте скрипт пж из С# в C++
class CSharpLanguage
{
public string Version {get;set;}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
[SerializeField] KeyCode keyOne;
[SerializeField] KeyCode keyTwo;
[SerializeField] KeyCode keyFree;
[SerializeField] KeyCode keyFour;
[SerializeField] Vector3 moveDirection;
private void FixedUpdate()
{
if (Input.GetKey(keyOne))
{
GetComponent<Rigidbody>().velocity += moveDirection;
}
if (Input.GetKey(keyTwo))
{
GetComponent<Rigidbody>().velocity -= moveDirection;
}
if(Input.GetKey(KeyFree))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if(Input.GetKey(KeyFour))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
private void OnTrigger(Collider other)
{
if(this.CompareTag("Player") && other.CompareTag("Finish"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
Было взято с сайта
https://www.codeporting.app/ru/
{
public string Version {get;set;}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
[SerializeField] KeyCode keyOne;
[SerializeField] KeyCode keyTwo;
[SerializeField] KeyCode keyFree;
[SerializeField] KeyCode keyFour;
[SerializeField] Vector3 moveDirection;
private void FixedUpdate()
{
if (Input.GetKey(keyOne))
{
GetComponent<Rigidbody>().velocity += moveDirection;
}
if (Input.GetKey(keyTwo))
{
GetComponent<Rigidbody>().velocity -= moveDirection;
}
if(Input.GetKey(KeyFree))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if(Input.GetKey(KeyFour))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
private void OnTrigger(Collider other)
{
if(this.CompareTag("Player") && other.CompareTag("Finish"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
Было взято с сайта
https://www.codeporting.app/ru/
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SceneComponent.h"
#include "Player.generated.h"
UCLASS()
class YOURGAME_API APlayer : public AActor
{
GENERATED_BODY()
public:
APlayer();
UPROPERTY(EditAnywhere)
TSubclassOf<AActor> Finish;
void KeyOnePressed();
void KeyTwoPressed();
void KeyThreePressed();
void KeyFourPressed();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
UPRIMITIVE_Generate_COMPONENT(Transform, RootComponent)
private:
FVector MoveDirection;
};
// Player.cpp
#include "Player.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
APlayer::APlayer()
{
PrimaryActorTick.bCanEverTick = true;
}
void APlayer::BeginPlay()
{
Super::BeginPlay();
MoveDirection = FVector(10, 0, 0);
}
void APlayer::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::One))
KeyOnePressed();
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::Two))
KeyTwoPressed();
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::Three))
KeyThreePressed();
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::Four))
KeyFourPressed();
}
void APlayer::KeyOnePressed()
{
AddActorWorldOffset(MoveDirection, true);
}
void APlayer::KeyTwoPressed()
{
AddActorWorldOffset(-MoveDirection, true);
}
void APlayer::KeyThreePressed()
{
UGameplayStatics::OpenLevel(this, FName(*GetWorld()->GetMapName()), false);
}
void APlayer::KeyFourPressed()
{
// Добавьте имя следующего уровня после "ExampleLevel"
UGameplayStatics::OpenLevel(this, "ExampleLevel", false);
}
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SceneComponent.h"
#include "Player.generated.h"
UCLASS()
class YOURGAME_API APlayer : public AActor
{
GENERATED_BODY()
public:
APlayer();
UPROPERTY(EditAnywhere)
TSubclassOf<AActor> Finish;
void KeyOnePressed();
void KeyTwoPressed();
void KeyThreePressed();
void KeyFourPressed();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
UPRIMITIVE_Generate_COMPONENT(Transform, RootComponent)
private:
FVector MoveDirection;
};
// Player.cpp
#include "Player.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
APlayer::APlayer()
{
PrimaryActorTick.bCanEverTick = true;
}
void APlayer::BeginPlay()
{
Super::BeginPlay();
MoveDirection = FVector(10, 0, 0);
}
void APlayer::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::One))
KeyOnePressed();
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::Two))
KeyTwoPressed();
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::Three))
KeyThreePressed();
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->IsInputKeyDown(EKeys::Four))
KeyFourPressed();
}
void APlayer::KeyOnePressed()
{
AddActorWorldOffset(MoveDirection, true);
}
void APlayer::KeyTwoPressed()
{
AddActorWorldOffset(-MoveDirection, true);
}
void APlayer::KeyThreePressed()
{
UGameplayStatics::OpenLevel(this, FName(*GetWorld()->GetMapName()), false);
}
void APlayer::KeyFourPressed()
{
// Добавьте имя следующего уровня после "ExampleLevel"
UGameplayStatics::OpenLevel(this, "ExampleLevel", false);
}
Я не умею
replace('#','++')
&C это не скриптовый язык а компилируемый, пральна грить транслируйте
&C это не скриптовый язык а компилируемый, пральна грить транслируйте