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 HuskyPanda213 · Jun 20, 2013 at 04:40 AM · gamesavelevelcreator

Level creator save bug.

I have a bug with a level creator save, when I start the game the GetPrefs type script is making like 30 objects and they all are in the same position and are the same color. Please Help.

Level Script.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class LevelCreator : MonoBehaviour {
     
     public static LevelCreator ins;
     
     public bool isAddBlock;
     
     public List<block> blocklist = new List<block>();
     
     public GameObject Spawnpoint;
     public GameObject Block;
     
     public int blockint;
     
     // Use this for initialization
     void Start () {
     ins = this;
     }
     
     void Update () {
     blockint = PlayerPrefs.GetInt("blockint");
     }
     
     public float x;
     public float y;
     public float z;
     public string color;    
     public int isSpawnpoint = 0;
 
     void OnGUI(){
         if(GUI.Button(new Rect(Screen.width - 100,5,100,25),"Save")){
             SaveBlocks();
         }
         if(!isAddBlock){
             if(GUILayout.Button("Add New Block")){
                 isAddBlock = true;
             }
         }
         if(isAddBlock){
             block temp = new block();
             GUILayout.BeginHorizontal();
             if(GUILayout.Button("+")){
                 x++;
             }
             if(GUILayout.Button("+ 10")){
                 x+=10;
             }
             GUILayout.Box("X: " + x);
             if(GUILayout.Button("-")){
                 x--;
             }
             if(GUILayout.Button("- 10")){
                 x-=10;
             }
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal();
             if(GUILayout.Button("+")){
                 y++;
             }
             if(GUILayout.Button("+ 10")){
                 y+=10;
             }
             GUILayout.Box("Y: " + y);
             if(GUILayout.Button("-")){
                 y--;
             }
             if(GUILayout.Button("- 10")){
                 y-=10;
             }
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal();
             if(GUILayout.Button("+")){
                 z++;
             }
             if(GUILayout.Button("+ 10")){
                 z+=10;
             }
             GUILayout.Box("Z: " + z);
             if(GUILayout.Button("-")){
                 z--;
             }
             if(GUILayout.Button("- 10")){
                 z-=10;
             }
             GUILayout.EndHorizontal();
             
             GUILayout.BeginHorizontal();
             if(GUILayout.Button("Blue")){
                 color = "blue";
             }
             if(GUILayout.Button("Green")){
                 color = "green";
             }
             if(GUILayout.Button("Grey")){
                 color = "grey";
             }
             GUILayout.EndHorizontal();
             
             GUILayout.BeginHorizontal();
             if(GUILayout.Button("Is Zombie Spawnpoint")){
                 isSpawnpoint = 1;
             }
             if(GUILayout.Button("Is Not Zombie Spawnpoint")){
                 isSpawnpoint = 0;
             }
             GUILayout.EndHorizontal();
             
             if(GUILayout.Button("Create Block")){
                 temp.x = x;
                 temp.y = y;
                 temp.z = z;
                 Addnewblock(color,x,y,z,isSpawnpoint);
             }
             if(GUILayout.Button("Back")){
                 isAddBlock = false;
             }
             GUILayout.Box("Player Spawnpoint at X-0,Y-0,Z-0. Player height is over 2 units, add make sure a ground is at -1 y");
             GUILayout.Box("Is zombie spawn: " + temp.isSpawnPoint + " Color = " + temp.color);
         }
     }
     
     public void Addnewblock(string color,float x,float y,float z,int spawnpoint){
         Vector3 pos = new Vector3();
         pos.x = x;
         pos.y = y;
         pos.z = z;
         if(color == ""){
             color = "grey";
         }
         
         block temp = new block();
         temp.color = color;
         temp.x = x;
         temp.z = z;
         temp.y = y;
         temp.isSpawnPoint = spawnpoint;
         blocklist.Add(temp);
         blockint++;
         PlayerPrefs.SetInt("blockint",blockint);
         if(spawnpoint == 0){
             if(color == "grey"){
                 GameObject newblock = Instantiate(Block,pos,Quaternion.identity) as GameObject;
                 newblock.renderer.material.color = Color.grey;
                 
             }
             if(color == "blue"){
                 GameObject newblock = Instantiate(Block,pos,Quaternion.identity) as GameObject;
                 newblock.renderer.material.color = Color.blue;
             }
             if(color == "green"){
                 GameObject newblock = Instantiate(Block,pos,Quaternion.identity) as GameObject;
                 newblock.renderer.material.color = Color.green;
             }
         }
         if(spawnpoint == 1){
             GameObject newspawn = Instantiate(Spawnpoint,pos,Quaternion.identity) as GameObject;
         }
         
     }
     
     public void SaveBlocks(){
         foreach(block bk in blocklist){
             PlayerPrefs.SetString("BlockColor" + blockint,bk.color);
             PlayerPrefs.SetInt("BlockSpawn" + blockint,bk.isSpawnPoint);
             PlayerPrefs.SetFloat("BlockX" + blockint,bk.x);
             PlayerPrefs.SetFloat("BlockY" + blockint,bk.y);
             PlayerPrefs.SetFloat("BlockZ" + blockint,bk.z);
         }    
     }
         
 }
 [System.Serializable]
 public class block{
     public string color = "grey";
     public int isSpawnPoint = 0;
     public float x;
     public float y;
     public float z;
 }



Saveprefs type script.

 using UnityEngine;
 using System.Collections;
 
 public class SaveCreate : MonoBehaviour {
     
     public int blockint;
     
     public GameObject Blockpre;
     
     public float x;
     public float y;
     public float z;
     public string color;
     public int spawnpoint;
     
     // Use this for initialization
     void Start () {
     blockint = PlayerPrefs.GetInt("blockint");
     GetLevel();
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     public void GetLevel(){
         for(int counter = 1; counter <= blockint; counter++){
             PlayerPrefs.GetString("BlockColor" + blockint);
             PlayerPrefs.GetInt("BlockSpawn" + blockint);
             PlayerPrefs.GetFloat("BlockX" + blockint);
             PlayerPrefs.GetFloat("BlockY" + blockint);
             PlayerPrefs.GetFloat("BlockZ" + blockint);
             Vector3 pos = new Vector3();
             pos.x = x;
             pos.y = y;
             pos.z = z;
             if(color == ""){
                 color = "grey";
             }
             
             if(spawnpoint == 0){
             if(color == "grey"){
                 GameObject newblock = Instantiate(Blockpre,pos,Quaternion.identity) as GameObject;
                 newblock.renderer.material.color = Color.grey;
                 
             }
             if(color == "blue"){
                 GameObject newblock = Instantiate(Blockpre,pos,Quaternion.identity) as GameObject;
                 newblock.renderer.material.color = Color.blue;
             }
             if(color == "green"){
                 GameObject newblock = Instantiate(Blockpre,pos,Quaternion.identity) as GameObject;
                 newblock.renderer.material.color = Color.green;
             }
             }
             //if(spawnpoint == 1){
             //    GameObject newspawn = Instantiate(Spawnpoint,pos,Quaternion.identity) as GameObject;
             //}
         }
     }
 }
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

14 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

Related Questions

Multiple Cars not working 1 Answer

preferences, load second time etc 1 Answer

How to save my terrain level? 1 Answer

Problem with acclerometer 0 Answers

Problem with BRDF Shader 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