How do I Instantiate an object that is half the size of the parent object?
I am trying to make a enemy that splits in Unity 3D when I press the key K. While doing this I have run into several problems. Firstly, whenever I try to make a copy of the object it always copies into the centre of the scene (0, 0, 0). What I want to happen is when the K key is pressed, the copies are spawned around the parent object with random distance between a maximum range and a minimum range. Secondly, whenever I try to scale the copies, it doesn't work as BoxColliders cannot be scaled. Finally, this isn't a problem but how do I limit the amount of times the clones can duplicate themselves. I will leave the code below for anyone willing to help.
Thank you if can help!!
public void Awake()
{
scaleChange = new Vector3(-0.10f, -0.10f, -0.10f);
}
void Update()
{
float xSpread = Random.Range(MinExpel, MaxExpel);
float ySpread = Random.Range(MinExpel, MaxExpel);
Vector3 spread = transform.position + new Vector3(xSpread, ySpread, 0);
if (Input.GetKeyDown(KeyCode.K))
{
CreateClones();
DestroySelf();
}
}
void CreateClones()
{
Instantiate(Clone, spread, Quaternion.Euler(0, 180, 0));
Clone.transform.localScale += scaleChange;
}
void DestroySelf()
{
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613022518im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to: Velocity or addForce to 2D (Instantiated?) Object 1 Answer
How can I change this script so that each instantiated prefab spawns a set amount faster 0 Answers
Adding a unique element from one list to another list 2 Answers
Hello there I have a Instantiate Issue 0 Answers
Only the last clone of my enemies can harm me, they all have the same script 0 Answers