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 Tim 1 · Nov 16, 2010 at 05:57 PM · spawning

Need help with easy scripting

Hello, I need help with something! I appreciate all help I can get! Thanks in advance//Tim

I want my object to spawn at random X position within for example -10 and 10. How can I make that happen? I also dont want any exact numbers, I want it to spawn at random time between for example 30 seconds and 45 seconds. This is how my script look like right now (i already made my object moving):

function Update () { transform.Translate(0, -0.1, 0 * Time.deltaTime); }

If you can add the code I need to make my spawn thingy work I would be awesome! Also some explanation to what you did =)

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

2 Replies

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

Answer by Scribe · Nov 16, 2010 at 06:13 PM

You might want to check this page out it has some explanation about random class and might be useful for what you want to do: Random.Range

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 Scribe · Nov 17, 2010 at 09:55 PM 1
Share

var YourObject : GameObject; //select the object you want to spawn

var RandPos = Random.Range(-10, 10); //the position

var RandInterval = Random.Range(30, 45); //the time interval

InvokeRepeating("SpawnObject", RandInterval, RandInterval);

//the function "SpawnObject" starts after 30-45 seconds and repeates every 30,45 seconds

function SpawnObject () {

 Instantiate(YourObject, Vector3(RandPos, 0, 0), Quaternion.identity);

}

I think this would work but you might have to tweak it to fit your needs

avatar image
1

Answer by Proclyon · Nov 16, 2010 at 06:15 PM

There's several questions actually

You will need "this" for random values:

[Random.value][2]  

and this for "spawning" anything:

Instantiate method

I won't write the code, like your last post said, you wanted to learn. Well you can't learn programming without doing it sorry, that'd be bad Q&A aswell for this site.

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Spawning an object in the direction of a mouse click? 1 Answer

bullets are spawning under me and they don't move 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

How would I go about enemy spawning? (C#) 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