I recently added a script to a cube so I can use WASD to move that cube, and it worked well. When I added a script that I made a few days ago, it just breaks. It freezes when I click play. I will post both of the codes, and they may not be efficient/what you guys would do (I have been coding for about a week, and I am 15, still VERY uneducated when it comes to programming. I use C# Btw).
The script that breaks it all is:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
//Ints/Doubles/Floats (Variables)
public double PlayerHealth = 100;
public double PlayerStrength = 50;
public double PlayerEndurance = 100;
public double PlayerIntelligence = 100;
public double PlayerPower = 200;
public double PlayerLevel = 10;
//public double PlayerXP = 0;
//public double NeededLevelXP= 100;
//public double Coins = 0;
//Strings/Arrays
// Use this for initialization
public void Start () {
PlayerHealth = (PlayerHealth * (PlayerLevel / 100) + PlayerHealth );
PlayerStrength = (PlayerHealth * (PlayerLevel / 100) + PlayerStrength);
PlayerEndurance = (PlayerEndurance * (PlayerLevel / 100) + PlayerEndurance);
PlayerIntelligence = (PlayerIntelligence * (PlayerLevel / 100) + PlayerEndurance);
PlayerPower = (PlayerPower * (PlayerLevel / 100) + PlayerPower);
//Runs a check to make sure Intelligence isn't an impossible value
Checker();
Checker2();
Checker3();
//Prints Health
LogHealth();
//Prints Strength
LogSrength();
//Prints Endurance
LogEndurance();
//Prints Intelligence
LogIntelligence();
//Prints Power
LogPower ();
}
public void LogHealth()
{
Debug.Log ("Player Health: (PlayerHealth)");
Debug.Log (PlayerHealth);
}
public void LogSrength()
{
Debug.Log ("Player Strength:");
Debug.Log (PlayerStrength);
}
public void LogEndurance()
{
Debug.Log ("Player Endurance:");
Debug.Log (PlayerEndurance);
}
public void LogIntelligence()
{
Debug.Log ("Player Intelligence:");
Debug.Log (PlayerIntelligence);
}
public void LogPower()
{
Debug.Log ("Player Power:");
Debug.Log (PlayerPower);
}
public void Checker()
{
while (true) {
if (PlayerIntelligence > PlayerHealth) {
PlayerHealth -= 40;
Debug.Log ("Your Intelligence was greater than your health, your new health is:");
Debug.Log (PlayerHealth);
} else {
break;
}
}
}
public void Checker2()
{
while(true){
if(PlayerIntelligence > PlayerPower + 150){
PlayerHealth = 0;
Debug.Log ("PlayerIntelligence was greater that PlayerPower, killed player");
Debug.Log (PlayerHealth);
} else {
break;
}
}
}
public void Checker3()
{
while(true){
if (PlayerIntelligence <= 0) {
PlayerIntelligence =+ 1500;
if (PlayerIntelligence >= 100) {
PlayerIntelligence = 100;
}
} else {
break;
}
}
}
// Update is called once per frame
void Update () {
}
}
And then the script that I just added for PlayerMovement is
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float PlayerMovementSpeed = 10f;
public float PlayerRotateSpped = 50f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * PlayerMovementSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.S))
{
transform.Translate(-Vector3.forward * PlayerMovementSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.D))
{
transform.Rotate(Vector3.up * PlayerRotateSpped * Time.deltaTime);
}
if(Input.GetKey(KeyCode.A))
{
transform.Rotate(-Vector3.up * PlayerRotateSpped * Time.deltaTime);
}
}
}
Reading these scripts, can anyone explain to me why my game just freezes upon playing? Sorry if this is in the wrong place, or proper information is not given. If you need more, let me know, keeping in mind that I have minimal knowledge of programming, obviously a little if I wrote these though. Thanks in advance!