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 /
  • Help Room /
avatar image
0
Question by alexander11 · Jan 20, 2016 at 06:16 AM · unity 5tilefor-loopclonesexecuteineditmode

How do i make a realtime tiling??Help

Hello im trying to make a real time([ExecuteInEditMode]) tile maker that a public float can be edited in the inspector to increase and decrease amount of TIles but i cant seem to delete the previous 3Dobjects if you know what i mean

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 public class floor : MonoBehaviour
 {
     public Transform Tile;
     public float TslotsX;
     public float TslotsY;
     void FixedUpdate()
     {
             for (int x = 0; x < TslotsX; x++)
             {
                 for (int y = 0; y < TslotsZ; y++)
                 {
                     DestroyImmediate(prefab);
                     Instantiate(Tile, new Vector3(x * 1.0f, 0, y * 1.0f), Quaternion.identity);
                 }
             }
     }
 }
Comment
Add comment · Show 3
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 incorrect · Jan 20, 2016 at 06:27 AM 0
Share

Why you can't delete them? Store them in a List and delete if you need to.

avatar image incorrect · Jan 20, 2016 at 06:30 AM 0
Share

Btw, don't use FixedUpdate() for such things. FixedUpdate is for physics-related things. Don't call anything each frame (using Update()) or every physics frame (using FixedUpdate()) if you don't need it to be done every frame.

avatar image alexander11 incorrect · Jan 21, 2016 at 05:40 AM 0
Share

oh so Fixedupdate is for physics woops :D

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by incorrect · Jan 20, 2016 at 06:44 AM

 using UnityEngine;
 using System.Collections;
 
 public class TilePlacer : MonoBehaviour
 {
     public GameObject TilePrefab;
 
     [SerializeField]
     private float TslotsX = 1f;
     [SerializeField]
     private float TslotsY = 1f;
     [SerializeField]
     private float tileStep = 1f;
 
     private void RemoveTiles()
     {
         GameObject[] oldTilesArray = new GameObject[transform.childCount];
 
         //Get an array of children; you can't destroy them by DestroyImmediate (transform.GetChild(i).gameObject) because their indexes will change every time you are destroying one
         for(int i = 0; i < transform.childCount; i++)
             oldTilesArray[i] = transform.GetChild(i).gameObject;
 
         //Destroy them
         foreach(GameObject oldTile in oldTilesArray)
             DestroyImmediate (oldTile);
     }
 
     [ContextMenu("Place Tiles")]
     private void PlaceTiles()
     {
         //remove old tiles if there are any
         RemoveTiles();
 
         //Place new ones
         for (int x = 0; x < TslotsX; x++)
         {
             for (int y = 0; y < TslotsY; y++)
             {
                 //Instantiate new tile and save a reference to it's Transform component
                 GameObject tileInstance = Instantiate(TilePrefab, new Vector3(x * tileStep, 0, y * tileStep), Quaternion.identity) as GameObject;
 
                 //Get this tile's transform component
                 Transform tileTransform = tileInstance.GetComponent<Transform>();
                 //Make this new tile a child of TilePlacer object for easier management
                 tileTransform.parent = transform;
             }
         }
     }
 }
 
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 alexander11 · Jan 21, 2016 at 05:39 AM 0
Share

thank's :D

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

42 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

Related Questions

Bizzare error with for loop and tex2D in HLSL shader 1 Answer

Counting the number of tiles in a path 0 Answers

Nav mesh stopping when on new tile 0 Answers

Loop function isn't updating 0 Answers

How to shoot spider man webs? 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