public void Subdivide() { Vector3 pos = gameObject.transform.position; gameObject.transform.position = spawner.Position(); Rigidbody2D rb = gameObject.GetComponent <Rigidbody2D>(); AsteroidUtils.ApplyImpulse(rb); if (health <= 0) { return; } CreateAsteroid(spawner, health - 1, pos); CreateAsteroid(spawner, health - 1, pos); }
private void AddComponents() { AsteroidUtils.ApplyImpulse(gameObject.GetComponent <Rigidbody2D>()); /* Collision Notification */ AsteroidCollision collision = gameObject.AddComponent <AsteroidCollision>(); collision.Initialize(this); /* Reallocator */ SystemManager.RegisterSystem(new AsteroidReallocator(gameObject.transform, spawner), new UnityEventBind(GameEvents.GameOver)); GameObject circleCollider = new GameObject("Circle Collider") { layer = Layers.SteeringAvoidance }; CircleCollider2D collider = circleCollider.AddComponent <CircleCollider2D>(); collider.radius = health / HealthSizeProportion * RandomUtils.MaxVertexDisplacement + 0.5f; circleCollider.transform.SetParent(gameObject.transform); circleCollider.transform.localPosition = Vector3.zero; }