Esempio n. 1
0
 /// <summary>
 /// This method is called by the RayCasting method.  If two(or three, etc), balls happen to be overlapping, then a ball can occlude other balls.  Because of this,
 /// Having the "useColliderAndRaycast" boolen checked, was kind of necessary.  (Because only the Collider, would penetrate a collection of balls).  Now we do a small sphere
 /// cast in the area the first ball was cut.  And if there were other balls really close, then we collect them, and this method gets called.  Here we loop through them, and destroy
 /// them as usual.  The parameter that is passed in is our gibs number.  Because the other possible occluded targets are soo close to our cut ball, it makes since the cut angle would
 /// be similiar, so we will just make it the same.  So we pass the current gibs int, when we call this method.
 /// </summary>
 /// <param name="gibsIntFromOtherBall"></param>
 public void CheckSwipeOverlap(int gibsIntFromOtherBall)
 {
     //loop through all elements in the overlapList.
     for (int i = 0; i < overlapList.Count; i++)
     {
         //if any are tagged "Ball" we then.....
         if (overlapList[i].gameObject.CompareTag(Tags.ballTag))
         {
             // ... create a gameobject Var and store the current element.
             GameObject gObj = overlapList[i].gameObject;
             // we use GetCompoent to get a reference to the gameobjects DestroyBall script
             DestroyBall destroy = gObj.GetComponent <DestroyBall>();
             //then we call "CutBall" on it, and pass in the gibs number that was passed, from the original cut ball (remember this ball is probably touching the first cut ball), so we will make the cut the same.
             destroy.CutBall(gibsIntFromOtherBall);
             //debug, from testing.  commented out for publish.
             //Debug.Log("Neighbor Ball number:" + i.ToString());
         }
     }
     //then we clear the list.  We can keep using this same list.
     overlapList.Clear();
     //Debug.Log("Clearing List, for use during next cuts...");
 }
Esempio n. 2
0
    /// <summary>
    /// OnTriggerEnter This Unity Function checks if any "Ball" are in our TriggerCollider.  There is a long
    /// collider that protrudes into the scene, that is activated when the slicer is moving.  Most of the time
    /// the ray-casting is responsible for the ball "destroy" but occasionally the slice collider is responsible.
    /// </summary>
    /// <param name="other"></param>
    public void OnTriggerEnter(Collider other)
    {
        //if the object in our trigger collider is a "Ball" then...
        if (other.CompareTag(Tags.ballTag))
        {
            //if the other object is also active in the scene hierarchy(we make this check because we also have a ray-caster destroying ball... we don't want them to get a hold
            //of the same ball simultaneously... so to be safe we ask... Is it still active? because if not it might be because the ray-cast already started killing it..
            if (other.gameObject.activeInHierarchy)
            {
                //commented for release.
                //Debug.Log("Collider is doing its job");

                //we assign our "gibsToUse" variable the returned value of the Method SpawnProperBallDebris()... (see that Method for better understanding).
                gibsToUse = SpawnProperBallDebris();

                //now we create a DestroyBall variable named "destroy".  We then grab the "other" gameObject that entered our trigger, and we cache its DestroyBall Component in our new
                //"destroy" variable using GetComponent<>();
                DestroyBall destroy = other.GetComponent <DestroyBall>();
                //then we call "CutBall()" on our destroy variable, and pass it our "gibsToUse" variable.
                destroy.CutBall(gibsToUse);
            }
        }
        //if the object in our trigger collider is not a "Ball", but it's a "bomb" then we have a similar approach but with a different class & method.
        if (other.CompareTag(Tags.bombTag))
        {
            //again we make sure that the object is in fact still active in the scene hierarchy... hopefully because we don't want to try to destroy it the same time as the ray-casting counterpart.
            if (other.gameObject.activeInHierarchy)
            {
                //commented out for release.
                //Debug.Log("Power-up/Bomb Being Destroyed Via Collider");

                //now we create a DestroyBomb var named "destroy", and we use GetComponent<>() to get and store other.gameObjects "DestroyBomb" script...
                DestroyBomb destroy = other.GetComponent <DestroyBomb>();
                //then we call ActivateDestructionPerObjectType() on our new destroy variable.
                destroy.ActivateDestructionPerObjecType();
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// This Method is responsible for "destroying" our ball if we swipe across them.  The ray-cast comes from the
    /// camera and ends at the location of the ball(after ScreenPointToRay().
    /// </summary>
    private void CheckForRaycastHit()
    {
        //create a RaycastHit var and name it hit;
        RaycastHit hit;
        //create a Ray named ray, and give it the value of ScreenPointToRay(our fingerPos)
        Ray ray = mainCamera.ScreenPointToRay(fingerPos);

        //Ray-cast into our scene but only to our custom layer mask (myBallAndPowerUpLayerMask)...
        //which only contains the "Ball", and "Bomb" Layers.  We are only ray-casting 100 units
        //into scene
        if (Physics.Raycast(ray, out hit, 100f, sliceableObjects))
        {
            //we store our hit object in a new GameObject we create named hitObj.
            GameObject hitObj = hit.transform.gameObject;
            //Debug.Log("Ray-cast is doing its job");

            //if the hitObj has a tag of "Ball"...
            if (hitObj.CompareTag(Tags.ballTag))
            {
                Vector3 hitBallPos = hitObj.transform.position;
                //make sure the obj is still active in the scene(make sure the onTriggerEnter event did not
                //already start deactivating this gameobject)
                if (hitObj.activeInHierarchy)
                {
                    //gibs to use is assigned the value that SpawnProperBallDebris() returns.  We will need
                    //this for later when we destroy the ball.
                    gibsToUse = SpawnProperBallDebris();

                    //we Create a variable labeled "destroy" and we GetComponent() on the hitObj.
                    DestroyBall destroy = hitObj.GetComponent <DestroyBall>();
                    //then we call the CutBall() method on our hitObj, and pass the gibsToUse var as a parameter.
                    destroy.CutBall(/*debrisRot,*/ gibsToUse);

                    //this portion is for overlapping balls.  Before you kind of had to have the (useColliderAndRaycast Checked), but now
                    //it can just be used for the fringe cases/as a backup.  Because we will do a small little OverlapSphere check at the hitObj's
                    //position...

                    //create an array and store the overlapping objects (within 4 units(remember everything is big in this example)
                    Collider[] overlappingBallColliders = Physics.OverlapSphere(hitBallPos, 4f, sliceableObjects);
                    //then we will add the array elements to our overlapList Collection
                    overlapList.AddRange(overlappingBallColliders);
                    //then we will call a method that will check the elements in the list.  (check tags, and then take appropriate action if needed)
                    CheckSwipeOverlap(gibsToUse);
                }
            }
            else
            {
                //else since the tag is not "Ball" and there was only 2 objects on our LayerMask(which is Balls & Bombs)
                //then it has to be a bomb... so we assume it is and move forward.
                if (hitObj.activeInHierarchy)
                {
                    //we again create a new variable but this time its for our Bomb class "DestroyBomb". We
                    // GetComponent on our objHit and then after words we call the "ActivateDestructionPerObjecType()".
                    DestroyBomb destroy = hitObj.GetComponent <DestroyBomb>();
                    //call the "ActivateDestructionPerObjecType()"
                    //it will destroy itself and activate effects accordingly.
                    destroy.ActivateDestructionPerObjecType();
                }
            }
        }
    }