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 Daniele122898 · Jan 08, 2017 at 09:30 AM · gameobjectdeletefindwithtag

Will delete objects in Editor but not in Build?

So i have a problem. In my Menu Screen i have an arsenal tab. There is a table where the gun hovers above it and when i hit the left arrow or right arrow it switches trough the weapons showing their prefab in the screen.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ArsenalManager : MonoBehaviour {
 
     public GameObject[] guns;
     public Transform spawnPosition;
     public int gunIndex;
     Transform instantiatedGun;
     int[] levelNeeded = new int[5];
     int currentLevel;
 
     
 
     private void Start()
     {
         for(int i = 0; i< guns.Length; i++)
         {
             levelNeeded[i] = i * 5;
         }
     }
 
     public void OnCall()
     {
         RenderGun();
     } 
 
     void RenderGun()
     {
         //GameObject toDelete = GameObject.FindGameObjectWithTag("ArsenalWeapon");
         DestroyImmediate(GameObject.FindGameObjectWithTag("ArsenalWeapon"));
         Transform clone = Instantiate(guns[gunIndex].transform,spawnPosition.position, Quaternion.Euler((gunIndex==0)?180:0 ,-90,0));
     }
 
     public void LeftButton()
     {
         if (gunIndex > 0)
         {
             gunIndex--;
             RenderGun();
         }
         else
         {
             return;
         }
     }
 
     public void RightButton()
     {
         if (gunIndex < 4)
         {
             gunIndex++;
             RenderGun();
         }
         else
         {
             return;
         }
     }
 
     public int[] OnAcceptClick()
     {
         int[] trueAndLevel = new int[2];
         currentLevel = PlayerPrefs.GetInt("level", 0);
         if(currentLevel >= levelNeeded[gunIndex])
         {
             PlayerPrefs.SetInt("currentgun", gunIndex);
             trueAndLevel[0] = 1;
             trueAndLevel[1] = 0;
             return trueAndLevel;
         }
         trueAndLevel[0] = 0;
         trueAndLevel[1] = levelNeeded[gunIndex];
         return trueAndLevel;
     }
 
 }

Now i assigned the Tag to the weapons and in the editor when i run the game it works perfectly fine. when i hit left or right the old gun gets deleted and the new model is showed.

As soon as i built it it doesnt work anymore.

I even downloaded the EditorTag Finder script and modivied it to possibly find those tags but it tells me there are no editor tags. what is the problem?

 // xeophin.net/code // // (c) 2010 Kaspar Manz // code@xeophin.net // // All rights reserved. //
 using System;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 [AddComponentMenu("Helper Scripts/List Objects By Tag")]
 
 ///
 
 /// This is a simple little script that lists all objects with a /// certain tag, in order to find wrongly tagged objects. ///
 public class TagFinder : MonoBehaviour
 {
     /// <summary>
     /// A list of tags to look for.
     /// </summary>
     public string[] tagsToFind = { "EditorOnly" };
     string sceneName;
 
     /// <summary>
     /// At the start of the game, this script lists all objects
     /// with the defined tags.
     /// </summary>
     void Start()
     {
         findTags();
         sceneName = SceneManager.GetActiveScene().name;
 
     }
 
     void findTags()
     {
         foreach (string tag in tagsToFind)
         {
             print("Objects tagged with '" + tag + "':");
 
             try
             {
                 GameObject[] objects = GameObject.FindGameObjectsWithTag(tag);
                 if (objects.Length != 0)
                 {
                     foreach (GameObject item in objects)
                     {
                         print("  " + item.name + " on layer " + item.layer);
                     }
                 }
                 else
                 {
                     print("  There are no objects with the tag '" + tag + "'.");
 
                 }
             }
             catch (UnityException ex)
             {
                 print("  The tag '" + tag + "' has not been found. Exception Message: " + ex.Message);
             }
 
         }
     }
 
     private void Update()
     {
         if(SceneManager.GetActiveScene().name != sceneName)
         {
             sceneName = SceneManager.GetActiveScene().name;
             findTags();
         }
 
         if (Input.GetKeyDown(KeyCode.T))
         {
             findTags();
         }
     }
 }
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

103 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

Related Questions

How to delete an instantiated GameObject 2 Answers

I need help with Deleting and Initiating a gameobject 1 Answer

How to assign GameObject to a instantiated prefab via Script(C#)? 2 Answers

How can you change a Ridgidbody2D from Kinematic to Dynamic at runtime with GameObject.FindWithTag("myObject") ? 0 Answers

Cannot properly access player position 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