Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 alexander11 · Aug 07, 2016 at 03:35 AM · c#unity 5gameobjectinstantiate3d

How do i Instantiate gameObjects in between multiple points?

Hello i am having some trouble trying to instantiate GameObjects in between multiple points, but i am not getting the results that i want. This is what i am trying to achieve in Pic1, and the results i am getting in Pic2 if anyone know's how to do this?

Pic1 alt text Pic2 alt text

Here is the code so you know what i have done

 using UnityEngine;
 using System.Collections;
 
 public class Points : MonoBehaviour {
 
     public Transform[] points;
     public GameObject GameObj;
     public float GameObjectAmount = 2;
     
     void Start () {
         for (int i = 0; i < points.Length; i++)
             Instantiate(GameObj, points[i].position / GameObjectAmount, Quaternion.identity);
     }
 
 }

@Fattie @StormMuller

capture03.png (7.2 kB)
capture04.png (12.5 kB)
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
0
Best Answer

Answer by StupidlySimple · Aug 07, 2016 at 06:43 AM

     // Yawn... Probably something like this. Didn't test it because... well, I'm working on my game at the moment and didn't want to clear the current scene for you :P
 public class Points : MonoBehaviour
 {
     public Transform[] points; // I'm assuming this is coordinate of all your sugar cube.
     public GameObject GameObj; // Object you want to duplicate
     public float GameObjectAmount = 2; // Why is this float, you cannot have "half" a game object ;)

     void Start()
     {
         duplicateObject(GameObj, (int) GameObjectAmount);
     }

     public void duplicateObject(GameObject original, int howmany)
     {
         howmany++; // Because Logic!
         for (int i = 0; i < points.Length-1; i++)
         {
             for (int j = 1; j < howmany; j++)
             {
                 Vector3 position = points[i].position + j * (points[i + 1].position - points[i].position) / howmany; // Because Logic!
                 Instantiate(original, position, Quaternion.identity);
             }
         }
     }
 }
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 alexander11 · Aug 07, 2016 at 10:38 PM 0
Share

Thanks very much.

avatar image alexander11 · Aug 07, 2016 at 11:36 PM 0
Share

By the way how i would i do this for void Update ? i'm a rookie at c# if you know any good tutorials on stuff like this i would like to know, Thanks again.

avatar image StupidlySimple · Aug 08, 2016 at 05:45 AM 0
Share

No idea what's you're asking for.

If you want this function inside Update(), you will crash your game as it will generate a bunch of gameObjects every frame that Update is being called. o_O?

  void Update()
 {
 duplicateObject(GameObj, (int) GameObjectAmount);
 }
avatar image alexander11 StupidlySimple · Aug 08, 2016 at 06:50 AM 0
Share

I know, but is there a way to generate it once, so i can position it where ever?

avatar image
0

Answer by breban1 · Aug 07, 2016 at 11:26 AM

I'm not sure what you are trying to do with the calculation:

 points[i].position / GameObjectAmount

But it looks wrong to me.

If I am reading your question correctly, I THINK you want to instantiate between the points...

 for (int i = 0; i < points.Length-1; i++)
 {
 Instantiate(GameObj, Mathf.Lerp(points[i].position, points[i].position, .5f), Quaternion.identity);
 }

Note the points.Lenght-1 in the loop, you'll need that or you will go out of bounds.

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

229 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 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

How do i get the LocalSize of an object? 2 Answers

transform.SetParent(null); Not Working 1 Answer

Removing instantiated objects?? 1 Answer

How do i Instantiate sub-Points with in Multiple Points?? 1 Answer

How do i Instantiate Objects to a Empty GameObject as a Child?? 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