- Home /
Instantiate 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. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem;
public class Hareket : MonoBehaviour
{
public int speed;
private Touch touch;
private float speedModifier;
public GameObject Ball;
public GameObject Balls;
private int door1= 5;
// Start is called before the first frame update
void Start()
{
speedModifier = 0.01f;
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.forward * speed * 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
);
}
}
}
private 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);
}
}
}
alt text
Your answer
Follow this Question
Related Questions
Instantiate buttons , each with a unique positioning 2 Answers
Destroying assets is not permitted to avoid data loss. 0 Answers
Instantiated GameObjects scale down based on screen size. (Mobile) 0 Answers
My objects instantiate at a strange z coordinate 0 Answers
Distribute terrain in zones 3 Answers