- Home /
 
 
               Question by 
               izotrone · Apr 14 at 12:20 PM · 
                c#animationinstantiateinstantiate prefab  
              
 
              Cloning an object around the center
I'm newby to unity and I wanted to clone the game called "Count Masters " but I have some issues with cloning my objects.
When I exit from the doors, my objects they bump into each other and go the other way. I want my clones around my first game object as in the original game.
Here is my piece of codes . If someone can help me I'll be so appreciated.
What I attempted

What It should like originally

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.InputSystem;
 
 public class Hareket : MonoBehaviour
 {
     public int hiz;
     private Touch touch;
     private float speedModifier;
     public GameObject Ball;
     public GameObject Balls;
     private int door1= 5;
 
     void Start ()
     {
         speedModifier = 0.01f;
     }
 
     void Update ()
     {
         transform.Translate(Vector3.forward * hiz * Time.deltaTime);
         if(Input.touchCount>0)
         {
             touch = Input.GetTouch(0);
             if(touch.phase == UnityEngine.TouchPhase.Moved)
             {
                 transform.position =new Vector3(
                     transform.position.x + touch.deltaPosition.x * speedModifier, 
                     transform.position.y,
                     transform.position.z + touch.deltaPosition.y *speedModifier
                 );
             }
         }
     }
     void OnCollisionEnter(Collision other) 
     {
         if(other.gameObject.tag.Equals("doorSide"))
         {
             Destroy(Ball);
         }
     }
     
     void OnTriggerExit(Collider other) 
     {
         if (other.gameObject.tag == "door" )
         {
             for (int i = 0; i < door1; i++)
             {
                 //GameObject yeni_top = Instantiate(Top,transform.position,Quaternion.identity);
                 GameObject new_ball = Instantiate(Ball,new Vector3(i,Ball.transform.position.y,i),Ball.transform.rotation);
                 new_ball.transform.parent = Balls.transform; 
                 new_ball.name = "new_ball" + (i+1); 
             }
                 
         }
     }
 }
 
                
                 
                countmasters.jpeg 
                (120.0 kB) 
               
 
                
                 
                ekran-resmi-2022-04-13-190202.png 
                (349.4 kB) 
               
 
              
               Comment
              
 
               
              Your answer