Exemplo n.º 1
0
    // public GameObject ability1Target;


    // Start is called before the first frame update
    void Awake()
    {
        Vector3 bombDirection = -Vector3.one;

        cam     = Camera.main;
        surface = LayerMask.GetMask("Terrain");
        DB      = GetComponent <DestroyBomb>();
    }
Exemplo 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();
            }
        }
    }
Exemplo 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();
                }
            }
        }
    }