Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This question was closed Jan 21, 2018 at 11:12 PM by expat1999 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by expat1999 · Aug 06, 2015 at 02:35 AM · instantiatecollision detectionspawning problemsendless runner

Why does this not work (Involves instantiating objects in response to a collision*)

Ok, so I am making an endless runner, and I am trying to make it so when the "player" object collides with a "marker" object it will spawn the next section of road (which contains another marker). All the road sections behind the player are deleted as they pass. My problem is that when the player collides with the marker, the next section of the road does not appear. I can't figure out what I did wrong.

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;
 
             Instantiate(objectToSpawn, spawnPoint.transform.position, Quaternion.identity);
 
             spawning = false;
         }
     }
 }
 

Just in case I am misunderstanding, "Instantiate" spawns the object correct? Notice that the "spawnPoint" is another object. If you need more information, just ask.

Thank You, expat1999

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 Priyanshu · Aug 06, 2015 at 05:42 AM 0
Share

code is correct.

For correct collision with trigger -

  1. One of the 2 colliders must be marked as Trigger.

  2. For collision to register. One of the 2 Colliders must be Rigidbody.

To check if collision is happening use Debug.Log

avatar image expat1999 · Aug 07, 2015 at 08:17 PM 0
Share

Thank you Prlyanshu! $$anonymous$$ade a really dumb mistake... On the bright side I now have some practice making questions on here :D

avatar image Priyanshu · Aug 08, 2015 at 11:33 AM 0
Share

no prob :)

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by expat1999 · Aug 07, 2015 at 11:44 AM

Commented by Prlyanshu

code is correct.

For correct collision with trigger -

One of the 2 colliders must be marked as Trigger.

For collision to register. One of the 2 Colliders must be Rigidbody.

To check if collision is happening use Debug.Log

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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trouble spawning endless platform 0 Answers

Spawn enemies so they aren't spawned on top of each other (C#) 1 Answer

Instantiate GameObjects inside a collider 1 Answer

A tricky problem with Particle Collisions 0 Answers

Spawn an object to a random spawn point from a list 2 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