I am new to unity and C# but not to curly brace languages. I am following the javascript tutorial but trying to do it with C# instead and have run into a complete lack of understanding and documentation.
I have created the Move1 class
using UnityEngine;
using System.Collections;
public class Move1 : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
}
}
I have attached this to the camera, but when I play the ‘game’ the W,A,S and D keys do not move the camera.
I’ve a feeling it is to do with the complete lack of instantiation of variable ‘transform’ etc, BUT no errors are highlighted in the editor and no errors are thrown when it runs - this makes it very difficult to make progress.
Can anybody show me what I am missing to make this incredibly simple task, and maybe point me at some documentation.
I have to say that I am very dissapointed with the C# documentation in unity.
That script works for me. I think there must be something else wrong with your scene. Perhaps the script isn’t attached to the right object, or maybe your scale is such that the object is only moving a tiny amount relative to the size of the scene. You should also check the input settings to make sure that it’s all wired up correctly and that the relevant axes are sensitive enough.
Not sure if WASD automatically works, you might have to configure that in the Input-settings. Does it work with the arrow keys? Input Settings are in Edit / Project Settings / Input - but I think WASD is in there by default, so that’s probably not it.
Not sure what’s wrong with that script at the moment, but for a start I’d try multiplying the results of Input.GetAxis(…) with Time.deltaTime (for movement that’s independent of framerate) and some “speed” value, maybe 50 for a start.
By doing that, you’ll be able to change those values in the inspector in the editor while playing.
The “engine variables” are always instantiated when the relevant component is available in the game object. For transforms, this is always the case (every game object has a transform), so that’s not the issue.
If you’re completely new to C#, it might be a good idea to first play around a little bit with C# before going into the details of Unity. C# in Unity is the same as any other C#, so any C# tutorial will do. Just a random one I found via Google:
Microsoft has quite a lot of resources on C#, and I think the Mono project is also providing some very useful documentation. If you have VMWare Fusion or Parallels at hand (and Windows), I can highly recommend using Visual Studio as IDE for scripting - you’ll hardly find any solution that’s more convenient to use (and Visual Studio Express is free).
Once you feel convenient with C#, converting some of the UnityScript (aka “JavaScript”) stuff to C# is a very good exercise to get an understanding of the Unity API (it’s a bit unfortunate because UnityScript is not really verbose so there’s quite a few things you’ll have to look up in the ScriptingReference).
In general: Keep the ScriptingReference open and look everything you don’t understand immediately up in the beginning. The API is the same for all languages (C#, Boo, UnityScript).
Which “curly brace languages” are you experienced with?