Пример #1
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.gameObject.tag == "Graviton")
     {
         coll.gameObject.GetComponent <Shatter>().ShatterFromCenter(body.velocity.magnitude);
         GravityGlobal.RemoveGravityObject(gameObject);
         Destroy(gameObject);
     }
 }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        if (boosterForce <= 0)
        {
            throw new UnityException("Rocket was initialized without a boosterForce. Are you missing a Rocket.Launch call?");
        }

        body = GetComponent <Rigidbody2D>();
        GravityGlobal.AddGravityObject(gameObject);
    }
Пример #3
0
    /// <summary>
    /// Creates a new instances of a sphere and scales it to the current shatter ratio.
    /// </summary>
    /// <returns>The newly created sphere.</returns>
    private GameObject InstantiateScaledBall()
    {
        var newPiece = Instantiate(subPiece);

        newPiece.transform.localScale = transform.localScale * shatterRatio;
        newPiece.GetComponent <Rigidbody2D>().mass = NewPieceMass;
        newPiece.transform.parent = piecesContainer;
        GravityGlobal.AddGravityObject(newPiece);
        totalNumberOfCreatedSubPieces++;
        return(newPiece);
    }
Пример #4
0
    /// <summary>
    /// Replaces current sphere with subspheres.
    /// Subspheres are forced outward from current sphere's center.
    /// </summary>
    /// <param name="shatterStrength">Magnitude of force scattering the subsphere.</param>
    public void ShatterFromCenter(float shatterStrength)
    {
        CreateSubPieces();

        var currentVelocity = body.velocity;

        foreach (var piece in piecesContainer.GetComponentsInChildren <Rigidbody2D>())
        {
            var currentSphereVelocity       = new Vector3(currentVelocity.x, currentVelocity.y, 0);
            var calculatedSubpiecesVelocity = currentSphereVelocity / newPiecesCount;
            piece.AddForce(((piece.transform.position - transform.position) * shatterStrength + calculatedSubpiecesVelocity), ForceMode2D.Impulse);
        }

        GravityGlobal.RemoveGravityObject(gameObject);
        Destroy(gameObject);
    }