コード例 #1
0
ファイル: CameraGun.cs プロジェクト: zrdumped/Deer
    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();
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: Projectile.cs プロジェクト: tmcfar/galacdecks
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == target && !finished)
        {
            Impact();
        }
        Forcefield field = other.GetComponent <Forcefield>();

        if (field != null)
        {
            Debug.Log("Hit field");
            field.OnHit(transform.position, -2, 1);
        }
    }
コード例 #3
0
ファイル: SimpleGun.cs プロジェクト: zrdumped/Deer
    // Update is called once per frame
    void Update()
    {
        // Activate on Left mouse button
        if (Input.GetMouseButtonDown(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.gameObject.GetComponent <Forcefield>();

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