Это мое первое приложение Untiy3d, и я пытаюсь создать экран приветствия, на котором вам нужно нажимать пробел, чтобы начать игру, хотя после нажатия пробела ничего не происходит.
Вот также небольшой скриншотпоказывая мои выборы в редакторе Unity: http://prntscr.com/ly5o5b
Любая помощь будет оценена.
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 2000f;
public float upwardForce = 0f;
public float sideForce = 0f;
public GameObject waitScreen;
public GameObject mainPlayer;
public GameObject ingameUI;
private bool waitingToStartGame = true;
// Start is called before the first frame update
void Start()
{
mainPlayer.SetActive(false);
ingameUI.SetActive(false);
if (waitScreen != null)
{
waitScreen.SetActive(true);
}
else
{
waitingToStartGame = false;
Debug.LogError("waitScreen was not set in the inspector. Please set and try again");
}
if (mainPlayer != null)
{
mainPlayer.SetActive(false);
}
else
{
Debug.LogError("mainPlayer was not set in the inspector. Please set and try again");
}
}
void Update()
{
if (waitingToStartGame && (Input.GetKey(KeyCode.Space)))
{
waitingToStartGame = false;
if (waitScreen != null)
{
waitScreen.SetActive(false);
}
if (mainPlayer != null)
{
mainPlayer.SetActive(true);
ingameUI.SetActive(true);
}
}
}
void FixedUpdate()
{
if (!waitingToStartGame)
{
rb.AddForce(sideForce, upwardForce, forwardForce * Time.deltaTime, ForceMode.Force);
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
sideForce = 100f;
rb.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
Debug.Log("Key D pressed, player moved right");
sideForce = 0f;
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
sideForce = -100f;
rb.AddForce(sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
Debug.Log("Key A pressed, player moved left");
sideForce = 0f;
}
}
}
}