Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 NicolusBuck · Jan 12, 2016 at 10:05 AM · c#unity 5gameobjectprefabprefabs

Game Object is Instantiating on same position

I am working on a small project . But now I have come across a problem . The problem is the prefab is instantiating on the same position .

I want to instantiate a box end to end . The basic set up is as follows : -

alt text alt text

Image 3 -- http://s10.postimg.org/a2cqtappl/image.png

Box game object has a parent empty object (Start_point) , and a child empty object (end point) . Those marks the Start and End of that game object .

The game a empty game object (Tile_Gen) which has a C# script as follows :-

 using UnityEngine;
 using System.Collections;
 
 public class Tile_Gen : MonoBehaviour 
 {
 
    public GameObject G_O_01 ;
 
    public GameObject Current_Tile ;
 
    public Vector3 Start_Position_Of_Path ;
 
 // Use this for initialization
 void Start () 
 {
     Start_Position_Of_Path = Current_Tile.transform.GetChild(0).transform.GetChild(0).position;
     Instantiate(Current_Tile , Start_Position_Of_Path , Quaternion.identity);
 
 }
 
 // Update is called once per frame
 void Update () 
 {
     Path_Generator ();
 }
 
 public void Path_Generator()
 {
     Instantiate(G_O_01 , Start_Position_Of_Path , Quaternion.identity);
 // End of tile position = start tile position
     Start_Position_Of_Path = G_O_01.transform.GetChild(0).transform.GetChild(0).position;   
     print (Start_Position_Of_Path);
 }
 }

Here G_O_01 is Start_point prefab , Current_Tile is Start_point .

But this is not instantiating as I wanted . This instantiates all the object at one place .

But I want something like one behind the another , like this :-

Image 4 -- http://s9.postimg.org/ctwm25m5b/image.png

So Please help me to figure it out .

Regards NB :)

1.png (47.3 kB)
2.png (59.4 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

Answer by Stefan02 · Jan 12, 2016 at 03:27 PM

Hello you only need to move Start Point for x meters ( x=lenght of path) every time when you instantiate new obj, its easy

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 NicolusBuck · Jan 12, 2016 at 04:32 PM 0
Share

Thanks for the reply :) . Can you elaborate ? Regards :)

avatar image
0

Answer by JimNero_009 · Jan 13, 2016 at 12:53 PM

To elaborate on Stefan's answer; This seems to be a very complicated way of doing things. If you know the size of your prefab, why not just keep track of the position vector of each prefab you place? For example, at the start you instantiate one prefab at one given point which you can set publicly. Keep track of that vector in your code and after placing the prefab, increase the vector by one unit in the direction you want to go in and then place another prefab at that point. Continue until you get bored.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to tell at runtime if a GameObject is a prefab 3 Answers

How to destroy a particular clone on touch/mouse? 1 Answer

Spawned tree not falling 1 Answer

Create with code 2.2 pizza not shooting 1 Answer

Setting public GameObject to a different Prefab through code 0 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