So basically I created a first person controller and then created a new javascript (NewBehaviourScript) to add a running function.
For now I would like the k key to make the character run but it’s not working. Maybe I am not connecting the script properly to the fp controller?
#pragma strict
var RunSpeed : float = 30.0;
function Start () {
}
function Update () {
if (Input.GetButton ("k")){
transform.Translate(Vector3.forward * RunSpeed);
}
}
I made a variable called RunSpeed so that when a key is pressed in this case k, vector3.forward is transformed by the amount in the RunSpeed variable.
Or maybe Vector3.Forward is the wrong variable to change? Anyway after I created this I dragged it into the first person controller in the hierarchy
I am quite new to programming so sorry for my ignorance
Unity provides a fp controller but can we modify that controller by adding new things like running or even crouching? If so how do you link the script to the fp controller. I dragged it into the heirarchy and then when I clicked on the fp controller right at the bottom there was a ticked checkbox on the script so the script must be wrong?
How do you setup the input button? I went into Project Settings > Input and I couldn’t find “running” input I created for r so am I doing something wrong?
is a first person controller a game object? So can I do
Debug.Log(name + " - Is Working"); // GameObject name and message
what would I put in ‘name’ to test if the k (running) is working?
Sorry again I am new to Unity and java programming
Other than that does the code look fine, so if I were in the right settings and setup the input would the running work?
Also another question out of curiosity.
Is it better to create a script, drag it into the first person controller then edit the script from there and save it…
or
Create the java script, open it up, do programming, save it and only after drag it into the fpcontroller