Reputation: 11
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);
}
}
Upvotes: 0
Views: 1039
Reputation: 573
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.
Upvotes: 1