Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Gilead7 · Aug 13, 2016 at 07:54 PM · c#triggerswitchcase

Adjusting location on save to avoid infinite loop.

Here's the situation. I have a trigger script that saves your game and loads another map. That works just fine, the problem is that it saves right on the trigger, so when you go back to the previous map, it loads the other map. I wanted to save an offset so you would transform to one or two spaces before the trigger primitive. Only it's not saving for whatever reason.

 public void PlayerAdjust(float CoordX, float CoordY, float CoordZ,  float amount, string axis) //float Rotation,
     {
         Debug.Log("X " +CoordX);
         Debug.Log("Y " +CoordY);
         Debug.Log("Z " +CoordZ);
         switch(axis)
         {
         case "x":
             CoordX=CoordX + amount;
             Debug.Log("calc X" +CoordX);
             
             break;
         case "y":
             CoordY=CoordY + amount;
             Debug.Log("calc Y" +CoordY);
             
             break;
         case "z":
             CoordZ=CoordZ + amount;
             Debug.Log("calc Z" +CoordZ);
             
             break;
         }
         Save();
     }

Here is the player adjust script. Do I need a return type?

Comment
Add comment · Show 2
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
avatar image EDevJogos · Aug 13, 2016 at 09:57 PM 0
Share

Sorry but i can't understand your question, can you formulate it a little more?

The maps are different scenes ? What does the Save(); do ?

avatar image Jessespike · Aug 14, 2016 at 08:04 AM 0
Share

Remove the switch-statement, is it really needed? You didn't provide any info about the player or what's being saved.

  public void PlayerAdjust(Vector3 offset)
  {
      player.transform.localPosition += offset;
      Save();
  }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Gilead7 · Aug 14, 2016 at 08:02 PM

Here is the Save function:

 public void Save()
     {
         var Personal=new JSONObject
         {
             {"Name" , PlayerName}, 
             {"Gender" , Gender }, 
             {"Body Type" , BodyType},
             {"Alignment" , Alignment},
             {"Guild" , Guild }, 
             {"Rank" , Rank },
             {"Form" , Form},
             {"Health" , Health},
             {"Hunger" , Hunger},
             {"Thirst", Thirst},
             {"Intoxication" , Intoxication},
             {"Fatigue" ,Fatigue},
             {"Encumbrance" , Encumbrance},
             {"Experience" , Experience}
             
         };
         
         var Stats = new JSONObject
         {
             {"Constitution" , Constitution},
             {"Strength" , Strength},
             {"Stamina" , Stamina},
             {"Dexterity" , Dexterity},
             {"Intelligence" , Intelligence},
             {"Wisdom" , Wisdom},
             {"Focus" , Focus},
             {"BattleSpeed" , Battlespeed}
         };
 
         var Vitals = new JSONObject
         {
             {"Life" , Life},
             {"Energy" , Energy},
             {"Endurance", Endurance}
         };
         
         var Skills =  new JSONObject
         {
             {"Light Melee Weapons" , LightMeleeWeapons},
             {"Medium Melee Weapons" , MediumMeleeWeapons},
             {"Heavy Melee Weapons" , HeavyMeleeWeapons},
             {"Light Ranged Weapons" , LightRangedWeapons},
             {"Medium Ranged Weapons" , MediumRangedWeapons},
             {"Heavy Ranged Weapons" , HeavyRangedWeapons},
             {"Light Armor" ,LightArmor},
             {"Medium Armor" ,MediumArmor},
             {"Heavy Armor" , HeavyArmor},
             {"Holy Armor" , HolyArmor},
             {"Holy Weapon",HolyWeapon},
             {"Wicked Armor" ,WickedArmor},
             {"Wicked Weapon",WickedWeapon},
             {"Block", Block},
             {"Parry" , Parry},
             {"Evade" , Evade},
             {"Critical Hit" ,CriticalHit}
             
         };
         
         var Money = new JSONObject
         {
             {"Copper" , Copper},
             {"Silver" , Silver},
             {"Gold" , Gold}
         };
         
         var Location = new JSONObject
         {
             {"Map", Application.loadedLevel},
             {"X" , CoordX}, 
             {"Y" , CoordY},
             {"Z" , CoordZ}
 
 //            {"Rotation" , Rotation}
 
         };
         Debug.Log("Saved X" + CoordX);
         Debug.Log("Saved Y" + CoordY);
         Debug.Log("Saved Z" + CoordZ);
 
         var Player = new JSONObject
         {
             {"Personal" , Personal},
             {"Stats" , Stats},
             {"Vitals" , Vitals},
             {"Skills" , Skills},
             {"Money" , Money},
             {"Location", Location}
         };
         
         Debug.Log(Player);
         File.WriteAllText(Application.dataPath + "/Player.json", Player.ToString());
     }

I wanted to set it up so that depending on where you were facing it would move you off the trigger on either x, y, or z. That's what the switch/case was all about. Also wanted to swing the player around so they are facing 180 degrees from the trigger(door) as if they came out. If that makes more sense.

Comment
Add comment · Show 1 · Share
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
avatar image Gilead7 · Aug 17, 2016 at 11:48 PM 0
Share

Hey Guys! I solved my own problem. What had happened was that the trigger was entered the second before the transform would have sent the player away, thus loading the other map/level. No matter how far away I set the coordinates, it didn't matter because the trigger was tripped.

Solution? I put in a new canvas and panel so that when the trigger goes off it asked you if you want to enter. Click on yes, level loads, click no, window closes.

When you exit the other level and return to where you were, the question pops up again. Just select no and you are golden!

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

209 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why would my switch's case be correct but the output is not? 2 Answers

Why does only one object respond, while more objects have exact same script? 0 Answers

Multiple Cars not working 1 Answer

I would like some help refactoring my code, I am working with switch cases concering the delivery of food items in my game 1 Answer

Updated Question if statement not executing case 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