Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BeyondLiving · Jan 17, 2014 at 06:43 AM · bugcrashrandomprojectfix

Random Project Crash While Coding *Code Included*

So, i was editing this script and randomly crashed my project apon saving. Once i tried loading my project again, it crashed. I then deleted the scene through the project folder. I made a new scene and then put my "Menu" script on an empty. I then clicked play. once in game, i clicked p to open up my menu and it crashed my project again. Also when i add my "PlayerStats" script to my new player it crashed right away. I have no idea what kind of code would actually crash my project.. If you would, please read through my code and see if you can figure it out. Thank you very very much! :)

"Menu" Code: static var paused : boolean = false; var pauseMenu = Rect(10,10,1500,850);

 //weapon upgrades
 var gunUpTier  = 1;
 var gunUpDamage = 5;
 var gunUpWepSpeed : float = 0;
 var gunUpCost = 1000;
 //armor upgrades
 var rocketUpTier = 1;
 var rocketUpDamage = 10;
 var rocketUpWepSpeed : float = 0;
 var rocketUpCost = 1000;
 //boots upgrades
 var otherUpTier = 1;
 var otherUpDamage = 100;
 var otherUpWepSpeed = 10;
 var otherUpCost = 1000;
 //CraftingWEAPON
 var weaponRarity : String;
 var weaponType : String;
 var weaponDamage = 0;
 var weaponSpeed : float = 0;
 var weaponToCraft = "";
 //EQUIPPED
 static var gunEquippedRarity : String;
 static var gunEquippedDamage = 0;
 static var gunEquippedDamageUpgrade = 0;
 static var gunEquippedSpeed :float = 0;
 
 static var rocketEquippedRarity : String;
 static var rocketEquippedDamage = 0;
 static var rocketEquippedDamageUpgrade = 0;
 static var rocketEquippedSpeed : float = 0;
 
 static var otherEquippedRarity : String;
 static var otherEquippedDamage = 0;
 static var otherEquippedDamageUpgrade = 0;
 static var otherEquippedSpeed = 0;
 
 
 function Update () {
      
     if(Input.GetKeyDown("p") && paused == false)
    {
    paused = true;
    Time.timeScale = 0;
    }
    else if(Input.GetKeyDown("p") && paused == true) {
    paused = false;
    Time.timeScale = 1;
 }
 }
 function OnGUI(){
 
 
 if(paused){
 pauseMenu = GUI.Window(0,pauseMenu,MainMenuGUI, "Pause Menu");
 
 }
 
 }
 function MainMenuGUI(){
 GUI.Box(Rect(5,20,200,150),gunEquippedRarity+" Gun Tier: "+gunUpTier);                        //GUI BOXES
 GUI.Box(Rect(210,20,200,150),rocketEquippedRarity+" Rocket Tier: "+rocketUpTier);
 GUI.Box(Rect(415,20,200,150),otherEquippedRarity+" Rocket Tier: "+otherUpTier);
 GUI.Box(Rect(210, 230, 405, 265),"Player Stats");
 GUI.Box(Rect(5,230,200,210),"");
 GUI.Box(Rect(620,20,165,475),"Crafting");
 GUI.Box(Rect(620,60,165,60),"");
 GUI.Box(Rect(450, 250,160,60),gunEquippedRarity+" Gun");
 GUI.Box(Rect(450, 315,160,60),rocketEquippedRarity+" Rocket");
 GUI.Box(Rect(450, 380,160,60),otherEquippedRarity+" Other");
 //player stats
 GUI.Label(Rect(215,255,100,20),"Cash: "+PlayerStats.cash);                    //PLAYER STATS LABELS    
 GUI.Label(Rect(215,400,2000,100),"Gun Damage: "+PlayerStats.playerGunDamage+"\n"
 +"Gun Speed: "+PlayerStats.playerGunWepSpeed+"\n"
 +"Rocket Damage: "+PlayerStats.playerRocketDamage+"\n"
 +"Rocket Speed: "+PlayerStats.playerRocketWepSpeed+"\n"
 +"Other Damage: "+PlayerStats.playerOTHERDamage+"\n"
 +"Other Speed: "+PlayerStats.playerOTHERWepSpeed);
 GUI.Label(Rect(215,295,100,20),"Armor: "+PlayerStats.playerArmor);
 GUI.Label(Rect(215,315,100,20),"Move Speed: ");
 GUI.Label(Rect(215,335,100,20),"Shoot Speed: ");
 GUI.Label(Rect(215,355,100,20),"Talent Points: "+PlayerStats.playerTalentPoints);
 //WeaponUPGRADE
 GUI.Label(Rect(70,35,100,20),"Gun Level: "+gunUpTier);                        //GUN UPGRADE LABELS    
 GUI.Label(Rect(45,55,100,20),"Damage + "+gunUpDamage);
 GUI.Label(Rect(45,75,100,60),"Shoot Speed - "+gunUpWepSpeed);
 GUI.Label(Rect(70,150,100,20),"Cost: "+gunUpCost);
 //ARMORUPGRADE
 GUI.Label(Rect(275,35,100,20),"Rocket Level: "+rocketUpTier);                //ROCKET UPGRADE LABELS    
 GUI.Label(Rect(250,55,100,20),"Damage + "+rocketUpDamage);
 GUI.Label(Rect(250,75,100,60),"Shoot Speed - "+rocketUpWepSpeed);
 GUI.Label(Rect(275,150,100,20),"Cost:  "+rocketUpCost);
 //OTHERUPGRADE
 GUI.Label(Rect(480,35,100,20),"Tier: "+otherUpTier);                        //OTHER UPGRADE LABELS    
 GUI.Label(Rect(455,55,100,20),"Damage + "+otherUpDamage);
 GUI.Label(Rect(455,75,100,20),"Shoot Speed + "+otherUpWepSpeed);
 GUI.Label(Rect(480,150,100,20),"Cost: "+otherUpCost);
 //CRAFTING
 GUI.Label(Rect(622, 60, 160, 20), "Weapon: "+weaponRarity+" "+weaponType);  //CRAFTING LABELS
 GUI.Label(Rect(622, 80, 160, 60), "Damage + " +weaponDamage);
 GUI.Label(Rect(622, 100, 160, 60), "Attack Speed + "+weaponSpeed);
 GUI.Label(Rect(622, 120, 160, 60), "Cost: " + 1000);
 //EQUIPMENT
 GUI.Label(Rect(455, 270,120,100), "Damage + "); //+gunEquippedDamage+"(+ "+gunEquippedDamageUpgrade")");          //EQUIPMENT LABELS
 GUI.Label(Rect(455, 290,120,100), "Attack Speed + "+gunEquippedSpeed);
 GUI.Label(Rect(455, 335,120,100), "Damage + ");// +rocketEquippedDamage+"(+ "+rocketEquippedDamageUpgrade")");
 GUI.Label(Rect(455, 355,120,100), "Attack Speed + "+rocketEquippedSpeed);
 GUI.Label(Rect(455, 400,120,100), "Damage + "); //+otherEquippedDamage+"(+ "+otherEquippedDamageUpgrade")");
 GUI.Label(Rect(455, 420,120,100), "Attack Speed + "+otherEquippedSpeed);
 
 if(GUI.Button(Rect(5, 445, 100, 50), new GUIContent( "Main Menu"))){
 
 }
 
  
 //weapon Upgrade button
 if (GUI.Button(Rect(55, 175, 100, 50),new GUIContent( "^Gun+^"))){ //GUN WEAPON UPGRADE BUTTON
 if(PlayerStats.cash >= gunUpCost){
 PlayerStats.cash -= gunUpCost;
 PlayerStats.playerBonusGunDamage += gunUpDamage;
 PlayerStats.playerGunWepSpeed -= gunUpWepSpeed;
 gunUpDamage -= gunUpDamage;
 gunUpDamage += 5;
 gunUpWepSpeed += .02;
 gunUpTier+=1;
 gunUpCost += 1000;
 if(PlayerStats.playerGunWepSpeed <= .2){
 gunUpWepSpeed -= .02;
 }
 
 }  
 }
 
 
 if (GUI.Button(Rect(260, 175, 100, 50), "^Rocket+^")){ //ROCKET WEAPON UPGRADE BUTTON
 if(PlayerStats.cash >= rocketUpCost){ 
 PlayerStats.cash -= rocketUpCost;  
 PlayerStats.playerBonusRocketDamage += rocketUpDamage;
 PlayerStats.playerRocketWepSpeed -= rocketUpWepSpeed; 
 rocketUpDamage += 10;
 rocketUpWepSpeed += .06;
 rocketUpTier+=1;
 rocketUpCost += 1000;
 if(PlayerStats.playerRocketWepSpeed <= .2){
 rocketUpWepSpeed -= .06;
 }
 }
 }
 
 if (GUI.Button(Rect(465, 175, 100, 50), "^Other+^")){
 if(PlayerStats.cash >= otherUpCost){
 PlayerStats.cash -= otherUpCost;
 PlayerStats.playerOTHERDamage += otherUpDamage;
 PlayerStats.playerOTHERWepSpeed += otherUpWepSpeed;
 otherUpTier +=1;
 }
 }
 
 if (GUI.Button(Rect(622, 40, 53, 20), "Gun")){ //CRAFT THE WEAPON BUTTONS
 if(PlayerStats.cash >= 1000){
 weaponToCraft = "Gun";
 CraftGun();
 PlayerStats.cash -= 1000;
 }
 }
 if (GUI.Button(Rect(676, 40, 53, 20), "Rocket")){
 if(PlayerStats.cash >= 1000){
 weaponToCraft = "Rocket";
 CraftRocket();
 PlayerStats.cash -= 1000;
 }
 }
 if (GUI.Button(Rect(730, 40, 53, 20), "Other")){
 if(PlayerStats.cash >= 1000){
 weaponToCraft = "Other";
 CraftOther();
 PlayerStats.cash -= 1000;
 }
 }
 
 if (GUI.Button(Rect(730, 125, 53, 20), "Equip")){ //EQUIP THE WEAPON BUTTON
 if(weaponToCraft == "Gun"){
 gunEquippedRarity = weaponRarity;
 gunEquippedDamage = weaponDamage;
 gunEquippedSpeed = weaponSpeed;
 }
 else if(weaponToCraft == "Rocket"){
 rocketEquippedRarity = weaponRarity;
 rocketEquippedDamage = weaponDamage;
 rocketEquippedSpeed = weaponSpeed;
 }
 else if(weaponToCraft == "Other"){
 otherEquippedRarity = weaponRarity;
 otherEquippedDamage = weaponDamage;
 otherEquippedSpeed = weaponSpeed;
 }
 }
 
                                                         //TALENT SYSTEM BUTTONS
 if (GUI.Button(Rect(10, 235, 60, 60), "Dmg + 10")){
 if(PlayerStats.playerTalentPoints >= 1){
 PlayerStats.playerBonusGunDamage += 10;
 PlayerStats.playerTalentPoints -= 1; 
 
 }  
 }
 
 if (GUI.Button(Rect(10, 300, 60, 60), "Dmg + 20")){
 if(PlayerStats.playerTalentPoints >= 1){
 PlayerStats.playerBonusGunDamage += 20; 
 PlayerStats.playerTalentPoints -= 2;  
 }
 }
 if (GUI.Button(Rect(10, 365, 60, 60), "Dmg + 30")){
 if(PlayerStats.playerTalentPoints >= 1){
 PlayerStats.playerBonusGunDamage += 30;  
 PlayerStats.playerTalentPoints -= 3; 
 } 
 }
 
 if (GUI.Button(Rect(75, 235, 60, 60), "Arm + 10")){
 if(PlayerStats.playerTalentPoints >= 1){
 PlayerStats.playerBonusRocketDamage += 10; 
 PlayerStats.playerTalentPoints -= 1;   
 }
 }
 if (GUI.Button(Rect(75, 300, 60, 60), "Arm + 20")){
 if(PlayerStats.playerTalentPoints >= 1){
 PlayerStats.playerBonusRocketDamage += 20;  
 PlayerStats.playerTalentPoints -= 2;  
 }
 }
 if (GUI.Button(Rect(75, 365, 60, 60), "Arm + 30")){
 if(PlayerStats.playerTalentPoints >= 1){
 PlayerStats.playerBonusRocketDamage += 30;
 PlayerStats.playerTalentPoints -= 3;    
 }
 }
 if (GUI.Button(Rect(140, 235, 60, 60), "O")){
    
 }
 if (GUI.Button(Rect(140, 300, 60, 60), "O")){
    
 }
 if (GUI.Button(Rect(140, 365, 60, 60), "O")){
    
 }
 
 GUI.Label(Rect(100,100,100,40), GUI.tooltip);
 }
 
 
 function CraftGun(){                                    //CRAFT GUN FUNCTION
 var rank : float = Random.Range(0,101);
 weaponType = "Gun";
 
 if(rank <= 60 && rank != 33){
 weaponRarity = "Common";
 weaponDamage = Random.Range(15,55);
 weaponSpeed = Random.Range(0.35, .65);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 }
 else if(rank >= 61 && rank <= 90){
 weaponRarity = "Rare";
 weaponDamage = Random.Range(35,70);
 weaponSpeed = Random.Range(0.25, .45);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 }
 else if(rank <= 100 && rank >= 99){
 weaponRarity = "Legendary";
 weaponDamage = Random.Range(60,90);
 weaponSpeed = Random.Range(0.15, .35);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 }
 
 else if(rank == 33){
 weaponRarity = "Impossible";
 weaponDamage = Random.Range(150,200);
 weaponSpeed = Random.Range(0.05, .1);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 }
 
 }
 
 function CraftRocket(){                                    //CRAFT ROCKET FUNCTION
 var rank = Random.Range(0,101); 
 weaponType = "Rocket";
 if(rank <= 60 && rank >= 0){
 weaponRarity = "Common";
 weaponDamage = Random.Range(85,140);
 weaponSpeed = Random.Range(1.5, 2.2);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 }
 
 else if(rank >= 61 && rank <= 98){
 weaponRarity = "Rare";
 weaponDamage = Random.Range(100,170);
 weaponSpeed = Random.Range(.8, 1.3);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 }
 
 else if(rank <= 100 && rank >= 99){
 weaponRarity = "Legendary";
 weaponDamage = Random.Range(120,260);
 weaponSpeed = Random.Range(0.35, .7);
 weaponSpeed = Mathf.Round(weaponSpeed * 100f) / 100f;
 Debug.Log(rank +"LEGENDARY"+"Damage: "+ weaponDamage +" attspeed "+weaponSpeed);
 }
 }
 
 function CraftOther(){
 weaponDamage = 0;
 weaponSpeed = 0;
 }

"PlayerStats" Code:

 var healthText :GUIText;
 var levelText :GUIText;
 var cashText :GUIText;
 var waveText : GUIText;  
 
 static var playerHealthCur = 400;
 static var playerHealthMax = 400;
 
 static var playerXpCur = 0;
 var playerXpMax = 500;
 
 static var playerLevel :int = 1;
 static var playerTalentPoints = 0;
 static var cash = 100000000000;
 static var playerGunDamage = 0;
 static var playerGunWepSpeed = 0;
 static var playerBonusGunDamage = 0;
 
 static var playerRocketDamage = 0;
 static var playerRocketWepSpeed = 0;
 static var playerBonusRocketDamage = 0;
 
 static var playerOTHERDamage = 0;
 static var playerOTHERWepSpeed = 0;
 static var playerBonusOTHERDamage = 0;
 
 static var playerArmor = 20;
 static var playerMoveSpeed = 0;
 
 
 
 function Start () {
 
 }
 
 function Update () {
 //set play GUN/ROCKET/OTHER Damages
 playerGunDamage = Menu.gunEquippedDamage + playerBonusGunDamage;
 
 playerRocketDamage = Menu.rocketEquippedDamage + playerBonusRocketDamage;
 
 playerOTHERDamage = Menu.otherEquippedDamage + playerBonusOTHERDamage;
 
 if(SpawnEnemies.newWave == true){
 SpawnEnemies.timeUntilNextWave = SpawnEnemies.waveSpacing;
 SpawnEnemies.timeUntilNextWave -= 1;
 }
 waveText.text = "Wave: "+SpawnEnemies.waveCur+" Time Until Next Wave: "+SpawnEnemies.timeUntilNextWave+" Enemies Remaining: "+SpawnEnemies.enemyCount;
 healthText.text = playerHealthCur+" / "+playerHealthMax;
 levelText.text = "Level: "+playerLevel+"  "+playerXpCur+" / "+playerXpMax;
 cashText.text = "Cash: "+cash+"$";
 if(playerHealthCur >= playerHealthMax){
 playerHealthCur = playerHealthMax;
 }
 if(playerXpCur >= playerXpMax){
 OnLevelUp();
 }
 if(playerHealthCur <=0){
 Destroy(this.gameObject);
 }
 if(cash <= 0){
 cash = 0;
 }
 }
 
 
 function OnLevelUp(){
 playerHealthMax +=50;
 playerHealthCur += playerLevel*50/2;
 playerXpMax += 1000;
 playerLevel += 1;
 playerTalentPoints += 1;
 }
 function OnTriggerEnter(target){
 if(target.tag == "enemy"){
 playerHealthCur -= (EnemyStats.enemyDamage - playerArmor/2);
 }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem Loading Project 1 Answer

Cannot open specific project -1 Answers

Every Game i build crashes on startup but works in the Editor 0 Answers

possible bug black bar when you re enter app lollipop 5 1 Answer

UnityException: Launching iOS project via Xcode4 failed. Check editor log for details. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges