It’s been maybe a couple of months since I last posted here on the Unity forums.
When I started out, I was going to use C# as the scripting language in my Unity games. I’m currently re-doing the prototype example in the book ‘Unity 3.x Game Development Essentials,’ and I decide to use JavaScript instead. Considering I create web pages of my own, I though learning JavaScript in Unity would be a great way to gain skills for JavaScript when I use that scripting language in my HTML documents.
As I’m new to JavaScript, I’m right now doing some research through some old JavaScript books I got a hold of, some I am doing my homework. I posted my source code for the script Shooter.js. I’m getting compile errors, and it’s over the ‘h’ and ‘v’ variables in the code. As the error messages say, ‘h’ and ‘v’ aren’t defined. Since I’m new to JavaScript, does anyone know how I’d go about defining these variables? I’m unsure how to do it, but I do know that it should probably go at the top of the file above the functions listed in the code. I’d appreciate any help that anyone can give on this. ![]()
#pragma strict
var bullet : Rigidbody;
var power : float = 1500;
var moveSpeed : float = 5;
function Start () {
}
function Update () {
transform.Translate(h, v, 0);
var h : float = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
var v : float = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
}