0

I am a novice to game development so I am following a space shooter unity tutorial. However, after copying the code for player movement completely to the word my code still doesn't compile, despite no errors showing. If possible could someone check my code and see if I have missed an error, if not what can I do to make my code compile?

Code:

using UnityEngine;

[System.Serializable]
public class Boundary {
    public float xMin,
    xMax,
    zMin,
    zMax;
}

public class PlayerController: MonoBehaviour {
    public float speed;
    public float tilt;
    public Boundary boundary;

    private Rigidbody rb;
    void Start() {
        rb = GetComponent < Rigidbody > ();
    }

    void FixedUpdate() {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.velocity = movement * speed;

        rb.position = new Vector3(
        Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax));

        rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    }
}
8
  • 2
    Did you attach the code to your player in the Editor? What do you mean it does not compile? You mean nothing happens and your player does not move? Commented Mar 1, 2019 at 9:33
  • @karel I copied and paste the code and it gets executed the way it is. I think it is not related to using System. Commented Mar 1, 2019 at 10:08
  • how do you mean "it gets executed the way it is"? Commented Mar 1, 2019 at 10:26
  • I meant the code gets executed without changing anything just copying and pasting. Commented Mar 1, 2019 at 10:47
  • 1
    it really isnt clear what problem you are having from your description - if the code is running, then its good - compiling it depends on what you're asking it, example: I have a scene I can run it in unity editor with ctrl+P, but I cant compile it because of fips on my PC. But I also get an error. What exactly are you doing can you give us a minimal reproducible example walk through on how to recreate this lack of compile include all steps Commented Mar 1, 2019 at 11:41

1 Answer 1

1

Unity compiles your code automatically every time that you enter to the editor, if there is some syntax error unity notifies you.

You should try to use Visual Studio instead of Visual Studio Code, in VS already has an addon to attach with Unity and debug your code.

Sign up to request clarification or add additional context in comments.

1 Comment

I see the 'attach to Unity' function, I will use that to try and debug my code, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.