• 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 /
This question was closed Jan 21, 2018 at 11:11 PM by expat1999 for the following reason:

Problem is not reproducible or outdated

avatar image
1
Question by expat1999 · Aug 08, 2015 at 10:20 AM · childrencollisionsinstantiationendless runnerrepeating

Endless Runner Code

Ok so I'm making an endless runner and I need it to instantiate the next part of the track every time the player reaches a "Marker" object. The collisions work and the next track section instantiates for the first marker. The position the track is created is based on an object that is a child of the marker (which is also part of the track prefab). My problem is that the 2nd section of track does not get instantiated and I do not believe the collisions are working properly either (The debug I have running does not show anything for the second marker). I also changed the speed of the player to make sure that wasn't a problem.

Here's the code:

 using UnityEngine;
 using System.Collections;
 
 public class MarkerCollisionCheck : MonoBehaviour {
     
     public GameObject objectToSpawn = null;
     //public GameObject spawnPoint = null;
     public bool spawning = false;
 
     void OnTriggerEnter(Collider other)
     {
         if(other.tag == "Player" && spawning == false)
         {
             spawning = true;
             Debug.Log (spawning);
 
             //Instantiate(objectToSpawn, spawnPoint.transform.Find("GroundSpawnPoint").position, Quaternion.identity);
             Instantiate(objectToSpawn, transform.FindChild("GroundSpawnPoint").position, Quaternion.identity);
 
             spawning = false;
         }
     }
 }


So what could be wrong? If you have any questions just ask :D

Thank You, expat1999

Comment
Add comment · Show 2
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 NoseKills · Aug 08, 2015 at 11:08 AM 1
Share

So have you debugged if the trigger happens or not ?

 void OnTriggerEnter(Collider other)
 {
     Debug.Log (other);
     Debug.Log (other.tag);
     Debug.Log (spawning);
 
     if(other.tag == "Player" && spawning == false)
     {

Also, if you are not using multithreading, your variable spawning is not needed.

avatar image expat1999 · Aug 09, 2015 at 07:52 AM 0
Share

Thank you! While I may have not been very thorough when trying to figure this out for myself I definitely will remember that in the future.

It turns out the "spawning" variable (which I accidentally left in there for a now obsolete script) was always true when the prefabs were spawned. I am still not sure why that is but getting rid of the variable fixed the original problem.

Thank You: expat1999

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Detect Collision between an Instantiated Object and a non Convex mesh collider? 0 Answers

Checking Child collisions through parents 1 Answer

hidden children / instantiating as child 1 Answer

how to create a repeating environment in a 3D endless runner game 0 Answers

How to detect OnClick on children of a 3D model 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