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 /
This question was closed Sep 30, 2019 at 04:03 PM by tormentoarmagedoom for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by ITSLEO · Sep 29, 2019 at 07:51 PM · scripting problemfunctionspawningsnake

Spawn and Destroy problem snake like

Hello everyone...so, i am making a game that has a "snake-ish" mechanic for the food spawn, let's say... When my game starts, it spawns the food prefab at a random location, and that's good. What i can't achieve is that when my player touches the food, that food piece disappiears and a new one is spawned again at a random location...i tried EVERYTHING. But nothing seems to work and it freaks me out :/ it just passes trhough and nothing happens...i really hope some of you can help me with this one!

i tried On collision enter, i tried calling the same spawn function from another script, i tried to make a new spawn function aswell...nada

Comment
Add comment · Show 1
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 Captain_Pineapple · Sep 29, 2019 at 08:29 PM 1
Share

Can you please share some more information on your setup? Whats inside of your Ontriggerenter? Does it not get called or just doesnt work? did you set up colliders correctly? do you have rigidbodys attached?


please provide more information. There will probably noone be able to help you like this.

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by tormentoarmagedoom · Sep 30, 2019 at 03:49 PM

Hello there.

You are almos in the correct solution. First, do you know what is not working? Is OnCollisionEnter beeing called?, Where is this script attached? If you attach it in the food, dont need to "find for the foods in the scene. Are you sure your food is tagged as food? etc...

You have to use OnCollisionEnter, but, first, take care there are 2 methods: OnCollisionEnter and OnCollisionEnter2D. One for each type of colliders 2D or 3D

Then, you need to be sure the cmethos is beeing called when the collision ocurs, a good way to know it is by using a Debug.Log command

Then, make sure everything is correct with the method (have colliders, not mark as trigger, with rigidbodies...

When you are sure the method is called, then staert thinking i how to make a new food, but while programing, if you are new, NEVER TRY more than 1 thing at once. Go step by step, and dont continue until you are sure one thing is working!

Good luck!

Comment
Add comment · Show 1 · 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 ITSLEO · Sep 30, 2019 at 03:53 PM 0
Share

Thanks for the answer, i fixed it myself but still ;) Have a nice day and good luck on your projects too!

avatar image
-1

Answer by ITSLEO · Sep 30, 2019 at 03:52 PM

Guys. I fixed it myself. So i'm posting with the hope that this might help you aswell. So let's start by saying that sometimes C# it's dumb and makes your code a useless piece of trash and desperation even if there are no errors and in theory it should work. Now...

If sometimes you need to check a collision to trigger something, and OnCollisionEnter doesn't work: use OntriggerEnter instead change "other" to "collider" use the gameobject tag to do stuff, not the rigidbody, but still, one of the two objects must have the rigidbody, and i suggest you to use the object that is more still as the one with the rigidbody :)

Comment
Add comment · Show 1 · 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 tormentoarmagedoom · Sep 30, 2019 at 04:03 PM 0
Share

First, C# it's not dumb, you just dont understand whats going on.

and in theory it should work..? Unity can not be aware of logic errors.

OntriggerEnter is for trigger coliders OnCollisionEnter is for non triger coliders

"hange "other" to "collider" use the gameobject tag to do stuff, not the rigidbody" .... Read the Unity Documentation before please.....

So please, dont do this... Some new people come here looking for knowledge and wisdom, cant come and start giving advices like this..

Follow this Question

Answers Answers and Comments

198 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

SteamVR - Spawning Prefab on Controller,SteamVR - Spawning Objects on Controller 0 Answers

Spawn an object with additional parameter 1 Answer

Function call is not working 0 Answers

How to alter c# script from a script in a different scene (i.e. display score in different scene) 2 Answers

Checking if a function has been called from another script 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