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() { }
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() { }