void OnMouse()
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (BallPrefab != null)
                {
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                    GameObject prefab = (GameObject)GameObject.Instantiate(BallPrefab, transform.position + transform.forward, Quaternion.identity);
                    prefab.GetComponent <Rigidbody>().AddForce(ray.direction * 55f, ForceMode.VelocityChange);
                    prefab.GetComponent <Rigidbody>().AddTorque(new Vector3(Random.Range(-20f, 20f), Random.Range(-20f, 20f), Random.Range(-20f, 20f)));
                }
            }

            if (Input.GetMouseButton(1) && curTime >= FireRate)
            {
                curTime = 0.0f;

                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, 500.0f))
                {
                    Forcefield ffHit = hit.transform.gameObject.GetComponent <Forcefield>();
                    if (ffHit != null)
                    {
                        ffHit.OnHit(hit.point, hitPower);

                        if (ParticlePrefab != null)
                        {
                            GameObject.Instantiate(ParticlePrefab, hit.point, Quaternion.identity);
                        }

                        if (ShieldHitSFX.Length > 0)
                        {
                            int index = Random.Range(0, ShieldHitSFX.Length);

                            for (int i = 0; i < 10; i++)
                            {
                                if (!ShieldHitSFX[index].isPlaying)
                                {
                                    break;
                                }
                                else
                                {
                                    index = Random.Range(0, ShieldHitSFX.Length);
                                }
                            }

                            ShieldHitSFX[index].transform.position = hit.point;
                            ShieldHitSFX[index].Play();
                        }
                    }
                }
            }
        }
        // Update is called once per frame
        void Update()
        {
            // Activate on Left mouse button
            if (F3DWeaponRangeController.isObserverActive && Input.GetMouseButton(0))
            {
                // Returns a ray going from camera through a screen point
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                // Casts a ray against colliders in the scene
                if (Physics.Raycast(ray, out hit, 500.0f))
                {
                    // Get Forcefield script component
                    Forcefield ffHit = hit.transform.GetComponentInParent <Forcefield>();

                    // Generate random hit power value and call Force Field script if successful
                    if (ffHit != null)
                    {
                        float hitPower = Random.Range(-2f, 2f);
                        ffHit.OnHit(hit.point, hitPower);
                        ReactSpeed = ffHit.ReactSpeed;
                        if (curTime >= ReactSpeed)
                        {
                            Instantiate(ShieldFlashLight, hit.point + hit.normal, Quaternion.identity);
                            Instantiate(ShieldHit, hit.point + hit.normal * 0.5f, Quaternion.identity);

                            if (ShieldHitFX != null)
                            {
                                AudioSource temp = ((Transform)Instantiate(ShieldHitFX[Random.Range(0, ShieldHitFX.Length)], hit.point, Quaternion.identity)).GetComponent <AudioSource>();
                                temp.volume -= Random.Range(0f, 0.25f);
                                temp.pitch  -= Random.Range(-0.03f, 0.03f);
                                temp.Play();
                            }

                            curTime = 0f;
                        }
                    }
                }
            }

            curTime += Time.deltaTime;
        }
示例#3
0
        // Update is called once per frame
        void Update()
        {
            // Activate on Left mouse button
            if (Input.GetMouseButton(0))
            {
                // Returns a ray going from camera through a screen point
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                // Casts a ray against colliders in the scene
                if (Physics.Raycast(ray, out hit, 500.0f))
                {
                    // Get Forcefield script component
                    Forcefield ffHit = hit.transform.GetComponentInParent <Forcefield>();

                    // Generate random hit power value and call Force Field script if successful
                    if (ffHit != null)
                    {
                        float hitPower = Random.Range(-2f, 2f);
                        ffHit.OnHit(hit.point, hitPower);
                    }
                }
            }
        }