- Home /
Question by
daleonard · Jan 21, 2018 at 08:14 AM ·
speedfirst-person-controller
Strange crash, please help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class AdditionalControls : MonoBehaviour {
// public GameObject target;
public static bool sneak;
public static float runBoost = 0;
public static float baseRunBoost = 0;
public RigidbodyFirstPersonController fpsScript;
void Start() {
runBoost = 0;
baseRunBoost = 0;
}
void Update () {
fpsScript.movementSettings.RunMultiplier = 1.5f + runBoost + baseRunBoost;
if (Input.GetKey (KeyCode.LeftControl)) {
sneak = true;
} else {
sneak = false;
}
if (sneak == true) {
transform.localScale = new Vector3 (1, 0.1f, 1);
fpsScript.movementSettings.ForwardSpeed = 2;
fpsScript.movementSettings.JumpForce = 0;
fpsScript.movementSettings.RunMultiplier = 0;
} else if (sneak == false) {
transform.localScale = new Vector3 (1, 1, 1);
fpsScript.movementSettings.JumpForce = 40;
fpsScript.movementSettings.ForwardSpeed = 7;
if (fpsScript.movementSettings.Running == true) {
while (fpsScript.movementSettings.RunMultiplier < 2.5f) {
runBoost += Time.deltaTime * 0.1f;
}
}
}
}
}
This is a script i have made for my character in my game. I want that when the player starts sprinting, it will take some time until the character reaches max speed. Now however as soon as i sprint, unity freezes and i have to "force quit" it. Help appreciated.
Comment
Answer by corpsinheretoo · Jan 21, 2018 at 08:20 AM
while (fpsScript.movementSettings.RunMultiplier < 2.5f) {
runBoost += Time.deltaTime * 0.1f;
}
You need something inside the loop which will modify fpsScript.movementSettings.RunMultiplier or I do not see how the loop will ever terminate.