예제 #1
0
    void pickWeapon()
    {
        if (currentWeapon == null)
        {
            RaycastHit[] hits;
            Vector3      dir = mGame.actCamera.transform.TransformDirection(0, 0, 10) + (mGame.actCamera.transform.position - transform.position);
            hits = Physics.SphereCastAll(transform.position, 0.5f, dir, 2f);
            if (hits.Length > 0)
            {
                foreach (RaycastHit hit in hits)
                {
                    Weapon_Main hitScript = hit.transform.gameObject.GetComponent <Weapon_Main>();
                    if (hitScript != null)
                    {
                        currentWeapon = hit.transform.gameObject;

                        hitScript.playerIn = true;
                        hitScript.senabled = true;
                        hitScript.jogador  = gameObject;
                        hitScript.canShoot = true;
                        hitScript.transform.GetComponent <Rigidbody>().detectCollisions = false;
                        wscript = hitScript;
                        currentWeapon.transform.parent = transform;
                        //laserEnabled=true;

                        if (currentWeapon.transform.Find("AimView") != null && transform.Find("MainView2") != null)
                        {
                            Transform mv2    = transform.Find("MainView2");
                            Transform mv     = transform.Find("MainView");
                            Transform target = currentWeapon.transform.Find("AimView");

                            Vector3    oldP = currentWeapon.transform.position;
                            Quaternion oldR = currentWeapon.transform.rotation;

                            currentWeapon.transform.position = (mv.position + transform.position) / 2;
                            currentWeapon.transform.rotation = Quaternion.Euler((mv.rotation.eulerAngles.x + transform.rotation.eulerAngles.x) / 2, (mv.rotation.eulerAngles.y + transform.rotation.eulerAngles.y) / 2, (mv.rotation.eulerAngles.z + transform.rotation.eulerAngles.z) / 2);

                            Transform ps = target.parent;
                            target.parent = transform;
                            mv2.transform.localPosition = target.localPosition;
                            mv2.transform.localRotation = target.localRotation;
                            target.parent = ps;


                            currentWeapon.transform.position = oldP;
                            currentWeapon.transform.rotation = oldR;
                        }

                        break;
                    }
                }
            }
        }
    }
예제 #2
0
 void dropWeapon()
 {
     if (currentWeapon != null)
     {
         //Weapon_Main script = currentWeapon.GetComponent<Weapon_Main>();
         wscript.playerIn = false;
         wscript.jogador  = null;
         wscript.canShoot = true;
         wscript.senabled = true;
         wscript.transform.GetComponent <Rigidbody>().detectCollisions = true;
         wscript.transform.GetComponent <Rigidbody>().velocity         = Vector3.zero;
         wscript = null;
         MainGame CONFIG = GetComponent <newPlayer>().CONFIG;
         if (CONFIG.FirstPersonCamera.GetComponent <FPSCamera>().target == transform.Find("MainView2"))
         {
             changeAim();
         }
         currentWeapon.transform.parent = null;
         currentWeapon = null;
     }
 }