예제 #1
0
    // Remove a fraction of Attachables. Add a force so they are blown away
    public void ExplodeAttached(float fractionToExplode = 0.5f)
    {
        int initialAttachCount = AttachCount;
        int toRemoveCount      = (int)(fractionToExplode * initialAttachCount);

        // Copy attachables to an array. This avoids errors when looping over a list that is changing in size
        AttachableController[] attachableList = new AttachableController[initialAttachCount];
        attached.CopyTo(attachableList);

        // Remove objects from the Player
        foreach (AttachableController attachableController in attachableList)
        {
            if (toRemoveCount <= 0)
            {
                break;
            }

            toRemoveCount--;

            // Detach the object from the Player and explode the object
            attachableController.Detach(this);
            Detach(attachableController);
            attachableController.rigidBody.AddExplosionForce(explodeDetachVelocity, attachableController.transform.localPosition, 3f, 3f, ForceMode.VelocityChange);
        }
    }
예제 #2
0
 public void Attach(AttachableController attachableController)
 {
     if (!attached.Contains(attachableController))
     {
         attached.Add(attachableController);
         Mass += attachableController.Mass;
         OnAttachedCountChanged(AttachCount);
     }
 }
예제 #3
0
 public void Detach(AttachableController attachableController)
 {
     if (attached.Contains(attachableController))
     {
         attached.Remove(attachableController);
         Mass -= attachableController.Mass;
         OnAttachedCountChanged(AttachCount);
     }
 }
예제 #4
0
 public virtual void OnAttachableCollision(Collision collision, AttachableController attachableController)
 {
     attachableController.Attach(controller);
 }
예제 #5
0
 public AttachableFreeState(AttachableController controller) : base(controller)
 {
     stateName = "Free";
 }
예제 #6
0
    // Objects in this state are attached to the player

    public AttachableAttachedState(AttachableController controller) : base(controller)
    {
        stateName = "Attached";
    }