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 Dark Age · Jan 03, 2016 at 12:14 PM · prefabtriggerdestroyoffset

Infinte runner ground loading on trigger not working

Hi guys, I know this is a topic that has probably been done to death but I have not been able to find a solution as yet in all the answers.unity world and google combined. Ok so here's the run down, I am doing a Diploma in interactive Gaming and one of my last units/modules is to make a game for mobiles, I have chosen to do an infinite runner based on a popular kids bedtime story (I have 4 kids) I have been following along with unity's infinite 2D runner as well as many others from coffeebreak and ninjacupcake83 (I have been using his the most as it closely resembles what I wish to achieve). I have Instantiated a prefab clone of my "floor" to begin with so the player can stand upon something, I have also added a collider trigger towards the end of the "floor" which is meant to instanitate the next bit of "floor" and then delete the prefab behind me. the problem is a warning that says this

"Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy(Object) GroundSpawn:OnTriggerExit(Collider) (at Assets/Scripts/GroundSpawn.cs:29)"

My code is as follows

     using UnityEngine;
     using System.Collections;
     
     public class GroundSpawn : MonoBehaviour
     {
         // Call prefab to assign
         public GameObject worldClone;
         
         // Offset for spawning ground
         public float groundOffset = 0
         ;
         
         // Prefabs position (x, y, z)
         public Vector3 groundSpawn = new Vector3 (0, 0, 0);
         
         // Box Collider set up with a enter trigger function
         void OnTriggerEnter (Collider other)
         {
             // Spawn ground on the z axis where collider centers
             groundSpawn = new Vector3 (0, 0, transform.position.z + groundOffset);
             Instantiate (worldClone, groundSpawn, Quaternion.identity);
     
         }
         
         // Box Collider set up with a exit trigger function
         void OnTriggerExit(Collider other)
         {
             // Removes prefabs on exit of Collider
             Destroy (worldClone);
         }
     }


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

1 Reply

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

Answer by vintar · Jan 03, 2016 at 10:08 PM

You are trying to destroy the asset you dragged onto the inspector. Use this modified Script.

     using UnityEngine;
      using System.Collections;
      
      public class GroundSpawn : MonoBehaviour
      {
          // Call prefab to assign
          public GameObject worldClone;
          GameObject _currentGround;
 
          // Offset for spawning ground
          public float groundOffset = 0 ;
          
          // Prefabs position (x, y, z)
          public Vector3 groundSpawn = new Vector3 (0, 0, 0);
          
          // Box Collider set up with a enter trigger function
          void OnTriggerEnter (Collider other)
          {
              // Spawn ground on the z axis where collider centers
              groundSpawn = new Vector3 (0, 0, transform.position.z + groundOffset);
              _currentGround = Instantiate (worldClone, groundSpawn, Quaternion.identity) as GameObject;
      
          }
          
          // Box Collider set up with a exit trigger function
          void OnTriggerExit(Collider other)
          {
              // Removes prefabs on exit of Collider
              Destroy (_currentGround);
          }
      }
 
Comment
Add comment · Show 2 · 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 Dark Age · Jan 04, 2016 at 03:47 AM 0
Share

Thank you I see were I was going wrong now. $$anonymous$$udos to you for pointing it out to me

avatar image Dark Age · Jan 04, 2016 at 04:17 AM 0
Share

Can I use a similar script to destroy it using a different trigger collider ? I am trying something different where I am moving the ground towards the player but the instantiated floor does not trigger a new clone when it passes into the trigger collider, I have set a box collider and rigidbody to the "floor" piece, but to no avail, TIA

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

43 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

Related Questions

Clones destroying each other. 1 Answer

Destroying Object OnTriggerEnter2D not working 1 Answer

Act like a Trigger only with specific object 0 Answers

Destroying prefabs breaking scripting for other prefabs 0 Answers

Trigger not working on Enemy Prefab 3 Answers


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