I am developing a car game. When i press down arrow car get reverse faster like going forward. Here i want to set the reverse speed limit to 30mph. Anyone know about set speed limit of car?
3 Answers
3Can you post some code? Is there a reason why you are not just using an if statement to check the current value of car speed and increase it only if its less than 30? Something like this:
if(speed < 30.0f) {
// keep increasing the speed
}
Could you do a debug.log on the name property of each item in audioClips? Maybe x.name is the wrong property to use for orderby...
– Rostam24hi @Rostam24 Debug.Log(audioClips[0].name); and Debug.Log(audioClips[19].name); both print the names of the audio clips successfully onto console. It is unusual though, that after that, the following error is thrown on the first Debug.Log > ArgumentOutOfRangeException: Argument is out of range. Parameter name: index
– boogie77Hmm given the trouble you are running into, perhaps it makes more sense to load the files via code as well? Put the files in a Resources folder, then load them into the array or list using Resources.LoadAll
– Rostam24for some reason that didn't work for me, but I'll keep in mind what worked for you so I know my mistake is probably elsewhere. Thanks for all your help @Rostam24 ! Ü
– boogie77You can use Mathf.Clamp to clamp the speed :]
float clampedSpeed = Mathf.Clamp(yourSpeedValue, minSpeedLimit, maxSpeedLimit);
@boogie77: http://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html Create a folder called 'Resources' and put it anywhere in the assets folder. Now place the files in the Resources folder you just created. Now you can access it via resources.load
– Rostam24You Can set the speed limit to 30 when the key press down
void Update()
{
if (Input.GetKeyDown (KeyCode.DownArrow)) {
speed = Mathf.Clamp( speed, 0f, 30f);
}
}
Thanks to all for quick help.
– vmvenkatThanks @Rostam24 Ü That doesn't throw any errors or warnings, but the list still remains unsorted. This is puzzling.
– boogie77