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 /
avatar image
0
Question by BNOCSK · Dec 04, 2019 at 11:23 AM · collisioninstantiate prefabcolider

Detect collision of a GO within an instantiated prefab, against my player.

Sorry for the confusing title, I'm still not sure the best way to describe things.

I have done a basic endless runner, I changed it a few weeks back so that the track scrolls towards origin, rather than the player infinitely scroll.

I have a Tilemanager that is responsible for creating the tiles - I recently added some collider and rigidbody components to vehicles on my tile, as below: alt text alt text

My issue is that I need to stop the tile manager scrolling the instantiated tiles and stop the score (accessible on TileManager) when one of the colliders, within my Instantiated prefab, hits my player.

At the minute, if I add:

  void OnCollisionEnter(Collision other)
     {
         GameOver();
     }
 
     private void GameOver()
     {
        
         Debug.Log("Dead");
     }

To the PlayerMovement script (on Player), the collision works and the note is triggered - However, when I add it to the TileManager script, it doesn't ever trigger.

I have tried adding the rigidbody to my player and removing it from the vehicles within Instantiated tiles but that didn't work either.

Is there any way I can do this? Sorry if my explanation isn't great.

Thanks a lot for any help.

tilemanager.jpg (45.4 kB)
car-components.jpg (198.4 kB)
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 Larry-Dietz · Dec 04, 2019 at 03:16 PM

How about giving the player script a reference to the tile manager, and in the OnCollisionEnter on the player, call a method in TileManager to handle whatever changes you want to happen, i.e. stop scrolling, etc...

-Larry

Comment
Add comment · Show 4 · 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 BNOCSK · Dec 04, 2019 at 04:36 PM 0
Share

Hey @Larry-Dietz, thanks for the response!

How do I reference one script from another without it being a component?

Can I just do:

 private GameObject tile$$anonymous$$anager;
 
 void Start() {
     tile$$anonymous$$anager = GameObject.FindObjectWithTag("Tile$$anonymous$$anager");
 }

Thanks :) if I can get hold of it, I can use it no problem, I just haven't gotten hold of it. I'll try the above when I'm in but if it's not going to work or there's a better way, let me know.

Thanks again.

avatar image Larry-Dietz BNOCSK · Dec 04, 2019 at 05:11 PM 0
Share

Your best best would be something like this, assu$$anonymous$$g only one Tile$$anonymous$$anager exists in the scene...

 Private Tile$$anonymous$$anager tile$$anonymous$$anager;
 
 void Start()
 {
     tile$$anonymous$$anager = FindObjectOfType<Tile$$anonymous$$anager>();
 }
 

The you can just directly call any public methods in tile$$anonymous$$anager, i.e.

 tile$$anonymous$$anager.PauseScrolling();


Hope this helps, -Larry

avatar image BNOCSK Larry-Dietz · Dec 04, 2019 at 09:58 PM 0
Share

Thank you, it did help! I feel stupid for how simple and obvious that was. Thanks for pointing me in the right direction

Show more comments

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

173 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 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

Box Colider not working properly 1 Answer

Sound volume on different colisions 1 Answer

Proper instantiate projectile with variables (C#) 1 Answer

Coliders Don't work 1 Answer

My Position suddenly changes 0 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