Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Ian9921 · Aug 03, 2018 at 05:38 AM · arrayarray of gameobjectssetfill

Wrong object always Instantiated

Okay, so I'm working on a system where if a player destroys an object, they may then place duplicates of that item. If no object has been destroyed, an empty object, or airBlock, is placed. I'm currently having an issue where no matter what, the empty object is always placed instead of the intended block. The following script is on every block, and handles destroying the objects and the like.

 var targeted : boolean = false;
 var destroyOrPlace : int = 1; //1 = null, 2 = place, 3 = destroy
 var delayTicks : int = 0;
 var objToLoad : GameObject;
 public var delayTotal : int;
 public var dirtBlock : GameObject;
 public var stoneBlock : GameObject;
 public var nullBlock : GameObject;
 
 function Update () {
     if (targeted == true){
         if (destroyOrPlace == 3)
         {
             delayTicks = delayTicks + 1;
             Debug.Log("ticks updated ");
         } else if (destroyOrPlace == 2)
             {
                 delayTicks = 0;
                 Instantiate(MainScript.inventoryStore[MainScript.selectCol, MainScript.selectRow], transform.position, transform.rotation);
             }
 
     } else {
         delayTicks = 0;
     }
     if (delayTicks == delayTotal) {
         if (MainScript.inventoryStore[MainScript.inventoryCol, MainScript.inventoryRow] == null){
             if (gameObject.name == "Dirt-Block (Clone)"){
                 objToLoad = dirtBlock;
                 MainScript.inventoryStore[MainScript.inventoryCol, MainScript.inventoryRow] = objToLoad;
             } else if (gameObject.name == "Stone-Block (Clone)"){
                 objToLoad = stoneBlock;
                 MainScript.inventoryStore[MainScript.inventoryCol, MainScript.inventoryRow] = objToLoad;
             } else if (objToLoad == null) {
                 objToLoad = nullBlock;
                 MainScript.inventoryStore[MainScript.inventoryCol, MainScript.inventoryRow] = objToLoad;
             }
         }
         Destroy(gameObject);
         Debug.Log("Destroyed");
     }
 }

Any help would be greatly appreciated, and I'm more than happy to provide additional information.

Comment
Add comment · Show 1
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 SamohtVII · Aug 03, 2018 at 05:51 AM 0
Share

Huge stab in the dark cause I can't quite understand the code but is the gameobject name "Stone-Block(Clone)" without a space between the name and clone?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AdityaViaxor · Aug 03, 2018 at 06:23 AM

Please provide additional information like what delayTotal you pass and when player destroy object which function is called on destroying object. though despite of all these information i think the problem is in inventory because when you want to instantiate object you go to inventory and fetch object by row and colom. So either inventory is getting wrong number or you havent set value for invetoryRow and colom.

Comment
Add comment · 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

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

105 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

Related Questions

Null first array index and shift rest by 1? 1 Answer

Call function only on the Object the player is interacting with. (when there are multiple copys of the object) 1 Answer

Missiles move to already destroy objects [Problem][Update] 4 Answers

Sorting an array of GameObjects based on its name. 3 Answers

how see if the array has been filled 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