Project not working in Build

Hi,

So I finished my first game yesterday, but I came to the conclusion that the player movement doesnt work in the build version. which kinda sucks. How can I solve this issue?

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

public class Player_Movement : MonoBehaviour
{
public Rigidbody rb;

    public float X_Axis;
    public float Z_Axis;
    public float force;

    public bool Forward_backward;
    public bool leftward_rightward;

    void Start()
    {
        GetComponent<Rigidbody>().freezeRotation = true;
        Forward_backward = true;
        leftward_rightward = true;
        force = 5f;
    }

    public void Update()
    {
        //Sideward
        if (Input.GetKey ("a"))
        {
            if (leftward_rightward == true)
            {
                leftward_rightward = false;
                Debug.Log("leftward_rightward is false");
            }
        }
        if (Input.GetKey("d"))
        {
            if (leftward_rightward == false)
            {
                leftward_rightward = true;
                Debug.Log("leftward_rightward is true");
            }
        }

        if (leftward_rightward == true)
        {
            X_Axis = force;
        }
        if (leftward_rightward == false)
        {
            X_Axis = force * -1;
        }

        Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
        if (Input.GetKey("w"))
        {
            rb.AddForce(new Vector3(0f, 0f, Z_Axis));
        }
        if (Input.GetKey("s"))
        {
            rb.AddForce(new Vector3(X_Axis, 0f, 0f));
        }

Edit: the leftward_rightward bits do work, its just the input of w and s that doesnt work.

Debugging!

To get started and help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?

Knowing this information will help you reason about the behavior you are seeing.

You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

https://discussions.unity.com/t/839300/3

How can you see the Console if the game is build, cause it works perfectly fine in the editor.

Did you read my post above?

Yeah I did but I don’t see a working solution

Let me copy-paste the second from last paragraph I posted:

It aint on a mobile device

Write the Debug.Log output equivalent to a UI window during testing. I use this everywhere:

private void MyDebug(string debug)
    {
       
        Debug.Log(debug);
        myText.text += "\r\n" + debug;
    }

Even in a release build, all Debug.Log statements are written to the log file. Just check the log file.

Thanks, that link helped me. I couldnt find it myself, can someone close this threat?