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
1
Question by 13yearoldceo · Apr 19, 2014 at 01:23 PM · instantiateclonefunction updatetransform.1 frame

my object instantiates to much

 en#pragma strict
 
 var rocket : boolean = false; 
 var generate : boolean = false; 
 var timer : float = 5;
 var skyrocket : Transform; 
 var min : float = 0;
 var max : float = 5; 
 var minz : float = 0;
 var maxz : float = 5;  
 var amount : float = 0; 
 var remake : float = 15;
 
 function Start () { 
 
 
 
 
 }
 
 function Update () { 
 
 if(amount >= 1) 
 generate = (false);
 
 if(rocket){ 
 timer -= 1 * Time.deltaTime;}  
 
 
 remake -= 1 * Time.deltaTime; 
 
 
 
 if(remake <= 0) 
 generate = (true);
 make(); 
 
 
 hello i am trying to clone an object once every 15 seconds but a whole bunch keeps being cloned i remove it out of d update function but it still do not work right.
 
 
 
   
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 fendorio · Apr 19, 2014 at 01:33 PM 0
Share

Could you post your make function?

avatar image 13yearoldceo · Apr 19, 2014 at 04:20 PM 0
Share

i just made a custom function i didn really know you can define the make function

1 Reply

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

Answer by fendorio · Apr 19, 2014 at 01:41 PM

Not actually implemented a co-routine in UnityScript but here goes.

 var trigger : bool = true;

 function MakeObject()
 {
       trigger = false; //Set trigger to false so MakeObject won't get called again
       GameObject.Instantiate(skyRocket);
       yield WaitForSeconds(900); //Wait for 900 secs (15 mins)
       trigger = true; //After the wait set trigger to true so the function will get 
                       //called on the next update function call.
 }

 function Update()
 {
     //Your code..
     if(trigger == true)
        {
              MakeObject();
        }
 }

That is totally off the top of my head, so might work, might not ;) Give it a try. You don't need the timer logic using this way.

So yeah we start off on the first update with trigger being true, so on the first call of update MakeObject will get called.

When we enter MakeObject it first sets trigger to false, so that the coroutine won't get called on the next update call (and any other update call within the next 15 minutes).

We then instantiate a new GameObject (clone the object), and call yield WaitForSeconds, simply put that means that the line under it where we set trigger to true, doesn't get executed for the 900 second wait.

After the 900 second wait trigger gets set to true. So in the next update function call trigger is true, so we call MakeObject again... thus another GameObject is instantiated after 15 minutes.

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 fendorio · Apr 19, 2014 at 01:50 PM 0
Share

As stated I haven't actually implemented such functionality in UnityScript, so any JS/unityScript guy/gal that can point out a flaw in the above please do comment!

avatar image 13yearoldceo · Apr 19, 2014 at 04:22 PM 0
Share

ok i will try it

avatar image 13yearoldceo · Apr 19, 2014 at 10:17 PM 0
Share

thx for d script i followed ur scripts guide lines and now it works

avatar image fendorio · Apr 19, 2014 at 10:25 PM 0
Share

Glad it works :P Upvote if you liked it that much lool xD. But seriously glad it worked, good luck with the project!

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

21 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

Related Questions

How can I assign a clone with a script to a variable? without drag & drop 1 Answer

How can I make a game object follow an instantiated game object? 1 Answer

Instantiate Object Problem 0 Answers

Instantiating a random dropped consumable item from many cloned objects 1 Answer

Instantiated GameObject's components are disabled 3 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