Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
  • Help Room /
avatar image
0
Question by MrGrantSquat · Nov 02, 2015 at 09:13 PM · instantiateduplicateendless runner

how do I duplicate an object and have it be in a different position?

I have been watching an endless runner tutorial on YouTube lately, but I am stumped on the part where the platforms are supposed to duplicate and move a little bit to the right so that the player can run endlessly. I however didn't do my platforms the same way as the guy in the video did his, I made mine in paint.net as one big platform that i wanted to use. He made his from 2d squares basically. I didn't want to do it exactly like he did but every time i use the instantiate code it either duplicates in the exact position. When I did try it his way it would duplicate them correctly and it would move right on the x axis as intended, however the platforms would be tilted 90 degrees when they should be flat. If anyone could help me with this problem i'm having I would gladly appreciate it.


This is how my platforms look and what it does with the script I have for it.

alt text


This is the code I wrote for the platforms.

 using UnityEngine;
 using System.Collections;
 
 public class PlatformGenerator : MonoBehaviour {
 
     public GameObject thePlatform;
     public Transform generationPoint;
     public float distanceBetween;
 
     private float platformWidth;
 
 
 
     // Use this for initialization
     void Start () {
         platformWidth = thePlatform.GetComponent<BoxCollider2D> ().size.x;
     
     }
     
     // Update is called once per frame
     void Update () {
         if (transform.position.x < generationPoint.position.x) 
         {
             transform.position = new Vector3(transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
 
             Instantiate (thePlatform, transform.position, transform.rotation);
 
         }
 
 
     }
  }
 

unityhelppic2.png (15.3 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 bubzy · Nov 02, 2015 at 11:22 PM

i would make a new variable for transform and store the vector3 in that temporarily like

 Transform tempTransform = new Transform();
 tempTransform.position = new Vector3(transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
 tempTransform.RotateAround(transform.position,new Vector3(0,0,1),90);
 Instantiate (thePlatform, tempTransform.position, tempTransform.rotation);

or something similar :)

Comment
Add comment · Show 3 · 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 MrGrantSquat · Nov 04, 2015 at 12:56 AM 0
Share

do i execute this inside the if statement i have?

avatar image bubzy MrGrantSquat · Nov 05, 2015 at 07:49 PM 0
Share

in Update() yes

avatar image jj4154 · Jul 26, 2016 at 11:58 AM 0
Share

i need help on this too, I put in your code but i get a error on ''Transform'' after ''new'' on the first line, please help me

avatar image
0

Answer by julianjulianov · Feb 05, 2021 at 08:25 PM

https://answers.unity.com/questions/1811659/how-to-create-a-duplicateclone-object-and-particip.html

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

35 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

Related Questions

Hello there I have a Instantiate Issue 0 Answers

Why does the instantiation of a prefab work well when the scene is first loaded, but then the cloned GameObjects are no longer displayed in the scene? 0 Answers

Why does the instantiation of a prefab work well when the scene is first loaded, but then the cloned GameObjects are no longer displayed in the scene? 2 Answers

How to destroy only the collided instance of prefab and not the original one? 0 Answers

Instantiate duplicate of inactive child in GameObject 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