Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 FLASHDENMARK · Dec 06, 2010 at 06:18 PM · instantiaterandomsnake

Instantiate a object after destroying a instantiated object.

Hello you all!

I am working on a snake alike game, just to get the feel for game development!

I have gotten a kind of apple spawn at a random location every time the game starts. It workes great, but when i destroy the object i collide with (apple) so it kinda picks it up or eats it, after that i dont know how to instantiate ONLY one more apple at a random location, and then repeat the proces.

Can you please help me and i will be greatful :)

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 skovacs1 · Dec 06, 2010 at 06:22 PM 0
Share

The simple answer is to simply instantiate once at a random location like you did before. If you include some more description and/or some of your code, it would be a lot easier to provide a clearer answer to your specific use case.

avatar image FLASHDENMARK · Dec 06, 2010 at 07:10 PM 0
Share

$$anonymous$$y code is:

var shrooms : Transform;

function Start () { var position = Vector3(Random.Range(-36,36),Random.Range(-1.517441, -1.517441), Random.Range(-23, 23)); Instantiate(shrooms, position, Quaternion.identity); }

Now i dont know how to instantiate it ONCE more and reapeat the process after that. The closet i have come to a soloution reasulted in hundreds of thousends (allmost) instantiated objecte.

1 Reply

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

Answer by Justin Warner · Dec 06, 2010 at 07:08 PM

So:

function Update () { var appleTarget = GameObject.FindWithTag("Apple");

if( appleTarget == null ) { SpawnOneApple(); }

}

function SpawnOneApple() { //Put code for spawning an apple here... }

This'll always make sure one apple is on the board, because if one is gone, it spawns one, but if their is one their, then appleTarget isn't null...

Hope that helps =).

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 FLASHDENMARK · Dec 06, 2010 at 07:38 PM 0
Share

Hmm.. it looks like it should work, and a do understand the code but unfortunetly it dose not work. But thanks :)

avatar image Statement · Dec 06, 2010 at 09:07 PM 0
Share

What doesn't work? Doesnt any apples spawn? Are apples spawning like crazy?

avatar image FLASHDENMARK · Dec 07, 2010 at 06:17 AM 0
Share

It dose not spawn any "apples".

avatar image Justin Warner · Dec 09, 2010 at 04:05 PM 0
Share

You might have to put the var appleTarget = ... outside of the function... and it should work if you put in your spawning code...

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

No one has followed this question yet.

Related Questions

How to Instantiate only once? 2 Answers

Instantiate Random Object at Random Position 1 Answer

Making more than one item appear on a chess board 2 Answers

Mulitple spawn points with random seed. 3 Answers

Puzzle + Grid Instantiate - Random 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