예제 #1
0
        void Update()
        {
            if (userNeedsToFixStuff)
            {
                return;
            }

            if (Input.GetMouseButton(1) && !guiBox.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
            {
                theCamera.fieldOfView = 30f;
            }
            else
            {
                theCamera.fieldOfView = 60f;
            }

            if (Input.GetMouseButtonDown(0) && !guiBox.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
            {
                GetComponent <AudioSource>().Play();
                Ray rayen = theCamera.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
                if (Physics.Raycast(rayen, out raycastHit, 100f))
                {
                    BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                    bulletHitInfo.hitTransform = raycastHit.transform;
                    bulletHitInfo.bulletForce  = (raycastHit.point - transform.position).normalized * bulletForce;
                    bulletHitInfo.hitNormal    = raycastHit.normal;
                    bulletHitInfo.hitPoint     = raycastHit.point;

                    raycastHit.transform.root.SendMessage("HitByBullet", bulletHitInfo, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
예제 #2
0
        void HitByBullet(BulletHitInfo_AF bulletHitInfo)
        {
            if (userNeedsToFixStuff)
            {
                return;
            }

            bloodClone = Instantiate(blood, bulletHitInfo.hitPoint, Quaternion.LookRotation(bulletHitInfo.hitNormal)) as ParticleSystem;
            ragdollControl.shotByBullet = true;
            bloodClone.transform.parent = bulletHitInfo.hitTransform;
            bloodClone.Play();
            Destroy(bloodClone.gameObject, 1f);

            if (bulletHitInfo.hitTransform.name.Contains("Head"))
            {
                ragdollControl.shotInHead = true;
            }

            StartCoroutine(AddForceToLimb(bulletHitInfo));
        }
        // This script should be added to the root containing the box

        void HitByBullet(BulletHitInfo_AF bulletHitInfo)
        {
            bulletHitInfo.hitTransform.GetComponent <Rigidbody>().AddForceAtPosition(bulletHitInfo.bulletForce, bulletHitInfo.hitPoint);
        }
예제 #4
0
        IEnumerator AddForceToLimb(BulletHitInfo_AF bulletHitInfo)
        {
            yield return(new WaitForFixedUpdate());

            bulletHitInfo.hitTransform.GetComponent <Rigidbody>().AddForceAtPosition(bulletHitInfo.bulletForce, bulletHitInfo.hitPoint);
        }