Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 pepperedereppep · Nov 13, 2010 at 03:10 AM · instantiatetransformdestroytranslate

instantiate,destroy,gain speed in time

Not sure if the topic makes any sense, but basically I'm trying to instantiate a sphere(prefab) every 1 second, destroy the sphere after 2-5 seconds, and all the while have the spheres translating in x axis and speeding up faster and faster

var balls:Transform; var bool:boolean=true; var speed:float=0;

function Update () { if(bool==true){ ballsIns(); } //balls.transform.position.x+=speed*Time.deltaTime; }

function ballsIns(){ bool=false; var balls=Instantiate(balls,Vector3.zero,Quaternion.identity); yield WaitForSeconds(1); bool=true; }

this code is not exactly working obviously. The balls instantiate, but they don't translate. The sphere prefab has a code to destroy itself after a few seconds. My main question here is how to write a code that would speed up the balls in time. I can't write the code within the sphere prefab itself because once it destroys itself it resets the value. Any help would be great. Thanks!

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 Eric5h5 · Nov 13, 2010 at 04:21 AM

To spawn the balls, you can have this script on some object in the scene, like the camera or an empty game object:

var instantiateInterval = 1.0; var destroyTimeMin = 2.0; var destroyTimeMax = 5.0; var ball : GameObject;

function Start () { InvokeRepeating("Spawn", .01, instantiateInterval); }

function Spawn () { var ballClone = Instantiate(ball); Destroy(ballClone, Random.Range(destroyTimeMin, destroyTimeMax)); }

You can have a script on the ball prefab which translates it on the x axis. For the increasing speed, there are a couple of possibilities, depending on the effect you want:

If you want each ball to have its own speed, you can have a speed variable on the manager script, which you assign to a speed variable on the ball's script, using GetComponent when you instantiate the ball prefab. You would increment the speed variable after instantiating each ball.

Or you could have a static variable in the manager script, which likewise is incremented after each instantiation, and the ball's movement script would multiply its speed by the static speed variable in the manager script. That way all balls would always be going the same speed.

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 pepperedereppep · Nov 13, 2010 at 05:19 AM 0
Share

That codes made it so much easier, and now everything works :) Awesome reply. Thanks for your time.

avatar image
0

Answer by Loius · Nov 13, 2010 at 03:59 AM

You already have the Speed variable; what's wrong with just doing

speed += Time.deltaTime * 0.1;

in Update?

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

How do I duplicate an object to work with a shootemup 0 Answers

Bullet Translation question 0 Answers

Can't remove instantiated prefab 0 Answers

Destroying & Then Spawning Quickly 1 Answer

Destroying assets is not permitted to avoid data loss. 6 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