- Home /
Input Shift name
Well i just added a sprint script to my character. Now I want to name the shift button onto the input thingy. Amean to go edit-project settings-input. My problem is this. 1)I read through many tutorials that i need my original name(How to I name this script) 2)How do i name the left shift to actually activate the sprint script? Ty in advance.Any help will be apreciated. Ty
Answer by 4illeen · Dec 16, 2011 at 08:14 PM
Inside the script you should have something like this
if (Input.GetButton("Sprint"))
DO THE SPRINT
"Sprint" is the name of your sprint key you need to setup in Edit->Project Settings->Input
to do so create a new button there or use any existing one you don't need. In the Name field you put the same name you have in your script - in my situation it's Sprint. In the Positive Button field write e.g left shift. If you want and alternative button, fill the field called Alt Positive Button with e.g right shift
1)I read through many tutorials that i need my original name(How to I name this script)
if it's a C# script, you need to name it just like the class inside it e.g public class SprintScript : $$anonymous$$onoBehaviour - then your script should be called SprintScript.cs I'm not sure for other languages
Answer by bula · Dec 17, 2011 at 10:15 AM
This is my script(full)
var maxForwardSpeed : float = 20.0;
var maxSidewaysSpeed : float = 20.0;
var maxBackwardsSpeed : float = 10.0;
var maxSprintSpeed : float = 30.0;
if (Input.GetButtonDown("Sprint"))
{
maxForwardSpeed = maxSprintSpeed ;
maxSidewaysSpeed = maxSprintSpeed ;
maxBackwardSpeed = 0 ;
}
if (Input.GetButtonUp("Sprint"))
{
maxForwardSpeed = maxForwardSpeed;
maxSidewaysSpeed = maxSidewaysSpeed;
maxBackwardsSpeed = 0;
maxSprintSpeed = 0;
}
I gone the sprint button in edit-project settings - input and i did this: 1)I named the it Sprint 2)I named the positive button "left shift" What is the problem cause it's not working at all
What you pasted just changes variables, what movement script do you use? Also when Sprint button is up the line`maxForwardSpeed = maxForwardSpeed;` does nothing, because it's already changed to maxSprintSpeed. You need something like your currentSpeed and change it to either maxForwardSpeed or maxSprintSpeed.
But first of all we need to see your movement script - did you use Unity's First (or 3rd) Person Controller prefab?
i am using fps movement script...(first person shooter) and what you want to say is this?
maxForwardSpeed = 20 ;
maxSidewaysSpeed = 20;
Best regards i'm waiting your answear
To change the speed of your character when the SPRINT button is being pressed you need to find out which variable the fps script uses for player's speed - let's say it's called speed. Then the script would look like this:
Start(){
speed = maxForwardSpeed; //Player will start with speed = 20.0 }
Update(){
if (Input.GetButtonDown("Sprint")) //When you push the button
speed = maxSprintSpeed; //change the speed to sprint speed, so speed = 30
if (Input.GetButtonUp("Sprint")) //When you stop pushing the button
speed = maxForwardSpeed; //change the speed to normal, so speed = 20
}
once again - speed is the variable your fps script uses as character's movement speed, maxSprintSpeed & maxForwardSpeed are the variables you set
Your answer
![](https://koobas.hobune.stream/wayback/20220613062138im_/https://answers.unity.com/themes/thub/images/avi.jpg)