Esempio n. 1
0
 public virtual void Kill()
 {
     if (!destroyed)
     {
         destroyed = true;
         int breakApartNumber = Mathf.FloorToInt(Random.Range(breakApartMin, breakApartMax));
         if (breakApartNumber > 0 && breakApartPrefab != null)
         {
             float radius     = breakApartPrefab.radius;
             float startAngle = Random.Range(0f, 360f);
             for (int i = 0; i < breakApartNumber; ++i)
             {
                 Vector3  pos   = VectorHelper.FromAzimuthAndElevation(startAngle + i * (360f / breakApartNumber), 0f) * breakApartPrefab.radius * breakApartDistanceMultiplier;
                 Asteroid child = Instantiate(breakApartPrefab, transform.position + pos, Random.rotation);
                 child.velocity = velocity + pos * Random.Range(breakApartSpeedMultiplierMin, breakApartSpeedMultiplierMax);
                 child.parent   = parent.GetBreakApartParent();
                 child.parent.AddObject(child);
                 child.startSpeedSet = true;
                 if (i == 0 && isShiny)
                 {
                     child.shinyChance = 1f;  //guarantee at least one shiny child asteroid
                 }
                 else
                 {
                     child.shinyChance = isShiny ? breakApartShinyChainChance : child.shinyChance * breakApartShinyChanceMultiplier;
                 }
             }
         }
         Destroy(collider);
         Despawn(true);
     }
 }