Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (!ContinuousFire)
        {
            if (Input.GetMouseButtonDown(0))
            {
                //Your standard ray cast. creates a ray, then stores information about what the ray hit in the 'hit' variable.
                //then casts the ray, and calls the BreakFunction() on whatever collider it hits...
                //provided that the collider is attached to a gameobject that also has the Breakable class attached.
                Ray        ray = thisCam.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100))
                {
                    if (hit.transform.GetComponent <Breakable> () != null)
                    {
                        Breakable ThisBreakable = hit.transform.GetComponent <Breakable> ();
                        if (IgnoreCrackFunction)
                        {
                            StartCoroutine(TemporarilyDisableCracking(ThisBreakable));
                        }
                        ThisBreakable.SendMessage("BreakFunction");
                    }

                    //these pass control to the functions below if the appropriate bools are set to true.
                    if (BreakNearbyBreakables)
                    {
                        BreakBreakables(hit.point);
                    }

                    if (addExplosiveForceToNearbyRigidbodies)
                    {
                        StartCoroutine(AddBoom(hit.point));
                    }

                    if (InstantiateParticleSystem)
                    {
                        AddBoomParticles(hit.point);
                    }
                }
            }
        }

        //clicking the mouse casts a ray at what you were pointing at on screen - then does stuff to the first collider it finds in the path of that ray.
        else if (ContinuousFire)
        {
            if (Input.GetMouseButton(0))
            {
                StartCoroutine(DelayBetweenCrackAndFire());
            }
        }
    }
Exemple #2
0
    public IEnumerator DelayBetweenCrackAndFire()
    {
        if (!RateOfFireSwitch)
        {
            Ray        ray = thisCam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                if (BreakNearbyBreakables)
                {
                    BreakBreakables(hit.point);
                }

                if (addExplosiveForceToNearbyRigidbodies)
                {
                    StartCoroutine(AddBoom(hit.point));
                }

                if (InstantiateParticleSystem)
                {
                    AddBoomParticles(hit.point);
                }
                if (hit.transform.GetComponent <Breakable> () != null)
                {
                    Breakable ThisBreakable = hit.transform.GetComponent <Breakable> ();
                    if (IgnoreCrackFunction)
                    {
                        StartCoroutine(TemporarilyDisableCracking(ThisBreakable));
                    }

                    ThisBreakable.SendMessage("BreakFunction");
                    RateOfFireSwitch = true;
                    yield return(new WaitForSeconds(RateOfFire));

                    RateOfFireSwitch = false;
                }
            }
        }
    }