Hi! I’m sure people have heard of the classic DOS game Skyroads. (And Skyroads X-Mas edition)
I am currently making a sort of Skyroads clone and here is my question.
In the original Skyroads game, you could hold UP or DOWN to increase/decrease your speed. (Basically, from 0 to 100) Once you let off of the keys it kept steady at that speed. (People who have played the game will understand)
I’m wondering how you would go about achieving this in Unity?
1 Answer
1
Skyroads! That was an awesome game. In any case, this is absurdly simple- I’m really not sure what the problem is here.
public float maxSpeed;
public float minSpeed;
public float acceleration;
float curSpeed = 0;
void Update()
{
// Move the thing!
transform.Translate(transform.forward * curSpeed);
// Accelerate the thing!
curSpeed += Input.GetAxis("Vertical") * acceleration;
// Stop the thing from going too fast!
curSpeed = Mathf.Clamp(curSpeed, minSpeed, maxSpeed);
}
Make a new C# script, and put all of that in there.
Hmm, I get an error "A namespace can only contain types and namespace declarations" after all four "float"s and after "void" I might could fix it but I have never learned C#, I use Javascript. Thanks for the reply, also. I am new to scripting in Unity (but know enough) and I am just wondering how someone else would go about this so I can understand an efficient way of doing it.
– CaptainIcy281Bluh, don't just put it at the top of the file! It has to be inside a class. I almost never post code that can just be copy-pasted into a file- you should read and understand it before you can use it.
– syclamothSorry! I should've realized. I actually was working on it after I posted my comment and I got it working. Thanks a lot. :)
– CaptainIcy281