• 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 Aug 08, 2019 at 06:59 PM by zacharif for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by zacharif · Jul 28, 2019 at 05:34 PM · 3drandomclones

How to clone randomly

I have a 3d game where you drag things off the world but I need a cloner that clones my object randomly from x-2 to x2 and goes faster eg: every ten seconds speed increases by original speed *1.5. The other posts did not work for me. I tried nothing but the other posts. Thanks for helping!

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

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by xxmariofer · Jul 28, 2019 at 07:35 PM

 public GameObject prefab;
 public float x;//i dont know what x is

 void Start() { StartCoroutine(Cloner()); }

 float frequence = 10;

 void Update() {
    if(timer > 10) {
       timer = 0; frequence = frequence / 1.5f;
     }
     timer += Time.deltaTime;
 }
 
 IEnumerator Cloner()
 {    
    while(true){
       yield return new WaitForSeconds(frequence);
       Insntiate(prefab, new Vector3(x - 2, x + 2), Quaternion.identity);
    }
 }


Comment
Add comment · Show 34 · 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 zacharif · Jul 29, 2019 at 06:54 PM 0
Share

Weird I got

Assets\Clone.cs(8,19): error CS1003: Syntax error, ',' expected

avatar image xxmariofer zacharif · Jul 29, 2019 at 06:58 PM 0
Share

i missed a ; in the Instantiate line, i code it here without inteligence

avatar image zacharif xxmariofer · Jul 29, 2019 at 07:00 PM 0
Share

Yeah i fixed that but now it says somthing else

avatar image zacharif · Jul 29, 2019 at 07:26 PM 0
Share

Now it just does not work, when I play the game nothing else happens ._.

Thanks for the help so far I will give you 2 reputation points.

avatar image xxmariofer zacharif · Jul 29, 2019 at 07:32 PM 0
Share

nothing happens? is the coroutine not getting triggered? add in update a Debug.Log(timer); and see if its updating correctly, and add inside the ienumerator next to the instantiate a Debug.Log("spawning"); if the spawning is getting printed the object is spawning but maybe far away or something depending on the x

avatar image zacharif · Jul 29, 2019 at 07:36 PM 0
Share

Oh sorry, it works but it spawns where my first guy was, and because you throw the guy off the world the other clone spawns there too!

avatar image xxmariofer zacharif · Jul 29, 2019 at 07:39 PM 0
Share

totally my fault change the instantiate line to this

 Instantiate(prefab, new Vector3(Random.Range(x + 2, x - 2), 0, 0), Quaternion.identity)
avatar image zacharif · Jul 29, 2019 at 07:44 PM 0
Share

Still does not work Edit: but 1 clone has made it!

avatar image zacharif zacharif · Jul 29, 2019 at 07:57 PM 0
Share

Also, most people would quit right now so thanks for the help again take 3 reputations.

avatar image xxmariofer zacharif · Jul 29, 2019 at 08:18 PM 0
Share

You are welcome :) $$anonymous$$ark It as correct for futuro readers

Show more comments
avatar image zacharif zacharif · Jul 29, 2019 at 11:19 PM 0
Share

I think so.

avatar image zacharif zacharif · Jul 30, 2019 at 10:07 PM 0
Share

Do you know how to make a "landing base" or an area just for my clones ins$$anonymous$$d? Like a spawn point.

avatar image xxmariofer zacharif · Jul 30, 2019 at 10:41 PM 0
Share

The troops get indtantiate in the terrain so creating a smaler terrain quad or box give the smaller terrain a new layer and make the ratcast only hit that layer

Show more comments
avatar image zacharif · Jul 31, 2019 at 04:58 PM 0
Share

Also, my box collider leaves the player now do you know how to glue the box collider on?

avatar image xxmariofer zacharif · Jul 31, 2019 at 05:02 PM 0
Share

if its leaves the player is because the physics is not getting updated, since the collider is "glued" by default, did you edit the fixed time value? or are yuo setting time.timescale to a value lower than 1?

avatar image zacharif xxmariofer · Jul 31, 2019 at 05:36 PM 0
Share

I'm not so I don't know what's happening!

Show more comments
Show more comments
avatar image
0

Answer by zacharif · Aug 05, 2019 at 05:38 PM

Ok, I debugged it and it said it worked all the time! But when I dug deeper it still clones after one was thrown off but it disappears! When I clicked on it it said all the stuff it should have but it was gone except for the box collider? Any ideas?

Comment
Add comment · Show 2 · 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 zacharif · Aug 07, 2019 at 12:49 AM 0
Share

Seems to be working with other objects.

avatar image zacharif · Aug 08, 2019 at 06:55 PM 0
Share

Oh, It just does not work with ragdolls, only a $$anonymous$$or set back

avatar image
0

Answer by zacharif · Aug 08, 2019 at 06:56 PM

FINAL CODE:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Clone : MonoBehaviour
 {
     public GameObject prefab;
     public float x=2;//i dont know what x is
     void Start() { StartCoroutine(Cloner()); }
     float frequence = 10;
     float timer = 0;
     void Update()
     {
         if (timer > 10)
         {
             timer = 0; frequence = frequence / 0.5f;
         }
         timer += Time.deltaTime;
     }
 
     IEnumerator Cloner()
     {
         while (true)
         {
             yield return new WaitForSeconds(frequence);
             Instantiate(prefab, new Vector3(Random.Range(0, 1), 0, Random.Range(0, 1)), Quaternion.identity);
             Debug.Log("Work!");
         }
     }
 }
 
 
 
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 xxmariofer · Aug 08, 2019 at 07:12 PM 0
Share

after more than 20 comments you just copied my very first comment, and post it as an answer, and accepted your own answer? "FINAL CODE" i mean you are even using the exact same vars names, didnt you even test my code? thats really rude.

avatar image zacharif xxmariofer · Aug 08, 2019 at 07:35 PM 0
Share

What? No! because your old code hade typos so I fixed those typos otherwise it would not work! If u want to have the answer than go ahead!

avatar image xxmariofer zacharif · Aug 08, 2019 at 07:45 PM 0
Share

that you fixed the typos? is this a joke? the typo was that one ; was missing, and you didnt even fix it it was the one who told you that was missing, you are the most unpolite guy i have ever met in unity answers. you literally copied my code, there is not aa single difference. it took you more than 30 comments to even realize my code was working from the start is unbelivable that you believe you can waste our time like this

avatar image zacharif xxmariofer · Aug 08, 2019 at 07:41 PM 0
Share

I chaged the typos!

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

140 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

Related Questions

Random Tile Generation 0 Answers

Move Enemy randomly in a range. 3D 0 Answers

Make objects randomly fall 1 Answer

How to generate a random trajectory when the ball is kicked ? 1 Answer

Random variable values? 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