コード例 #1
0
ファイル: FPSController.cs プロジェクト: galaxymacos/FPS
    // Use this for initialization
    void Start()
    {
        _audioSource    = GetComponent <AudioSource>();
        firstPersonView = transform.Find("FPS View").transform;
        charController  = GetComponent <CharacterController>();
        speed           = walkSpeed;
        isMoving        = false;

        rayDistance             = charController.height * 0.5f + charController.radius;
        defaultControllerHeight = charController.height;
        defaultCamPos           = firstPersonView.localPosition;

        playerAnimation = GetComponent <FPSPlayerAnimation>();

        weaponManager.weapons[0].SetActive(true);
        currentWeapon      = weaponManager.weapons[0].GetComponent <FPSWeapon>();
        currentHandsWeapon = handsWeaponManager.weapons[0].GetComponent <FPSHandsWeapon>();

        handsWeaponManager.weapons[0].SetActive(true);
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        firstPerson_View = transform.Find("FPS View").transform;
        charController   = GetComponent <CharacterController> ();
        speed            = walkSpeed;
        is_Moving        = false;

        rayDistance = charController.height * 0.5f + charController.radius;
        default_ControllerHeight = charController.height;
        default_CamPos           = firstPerson_View.localPosition;

        playerAnimation = GetComponent <FPSPlayerAnimations> ();
        weapon_manage.weapons [0].SetActive(true);
        current_Weapon = weapon_manage.weapons [0].GetComponent <FPSWeapon> ();

        handsWeapon_Manager.weapons [0].SetActive(true);
        current_Hands_Weapon = handsWeapon_Manager.weapons [0].GetComponent <FPSHandsWeapon> ();

        if (isLocalPlayer)
        {
            playerHolder.layer = LayerMask.NameToLayer("Player");
            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
            for (int i = 0; i < weapons_FPS.Length; i++)
            {
                weapons_FPS [i].layer = LayerMask.NameToLayer("Player");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Enemy");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
        }

        if (!isLocalPlayer)
        {
            playerHolder.layer = LayerMask.NameToLayer("Enemy");
            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
            for (int i = 0; i < weapons_FPS.Length; i++)
            {
                weapons_FPS [i].layer = LayerMask.NameToLayer("Enemy");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Player");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
        }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLook.Length; i++)
            {
                mouseLook [i].enabled = false;
            }
        }
        mainCam = transform.Find("FPS View").Find("FPS Camera").GetComponent <Camera> ();
        mainCam.gameObject.SetActive(false);

        if (!isLocalPlayer)
        {
            for (int i = 0; i < PlayerRender.materials.Length; i++)
            {
                PlayerRender.materials [i].color = playerColors [i];
            }
        }
    }
コード例 #3
0
    void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            if (!handsWeapon_Manager.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons [i].SetActive(false);
                }
                current_Hands_Weapon = null;
                handsWeapon_Manager.weapons [0].SetActive(true);
                current_Hands_Weapon = handsWeapon_Manager.weapons [0].GetComponent <FPSHandsWeapon> ();
            }

            if (!weapon_manage.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < weapon_manage.weapons.Length; i++)
                {
                    weapon_manage.weapons [i].SetActive(false);
                }
                current_Weapon = null;
                weapon_manage.weapons [0].SetActive(true);
                current_Weapon = weapon_manage.weapons [0].GetComponent <FPSWeapon> ();

                playerAnimation.ChangeController(true);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (!handsWeapon_Manager.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons [i].SetActive(false);
                }
                current_Hands_Weapon = null;
                handsWeapon_Manager.weapons [1].SetActive(true);
                current_Hands_Weapon = handsWeapon_Manager.weapons [1].GetComponent <FPSHandsWeapon> ();
            }

            if (!weapon_manage.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < weapon_manage.weapons.Length; i++)
                {
                    weapon_manage.weapons [i].SetActive(false);
                }
                current_Weapon = null;
                weapon_manage.weapons [1].SetActive(true);
                current_Weapon = weapon_manage.weapons [1].GetComponent <FPSWeapon> ();

                playerAnimation.ChangeController(false);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            if (!handsWeapon_Manager.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons [i].SetActive(false);
                }
                current_Hands_Weapon = null;
                handsWeapon_Manager.weapons [2].SetActive(true);
                current_Hands_Weapon = handsWeapon_Manager.weapons [2].GetComponent <FPSHandsWeapon> ();
            }

            if (!weapon_manage.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < weapon_manage.weapons.Length; i++)
                {
                    weapon_manage.weapons [i].SetActive(false);
                }
                current_Weapon = null;
                weapon_manage.weapons [2].SetActive(true);
                current_Weapon = weapon_manage.weapons [2].GetComponent <FPSWeapon> ();

                playerAnimation.ChangeController(false);
            }
        }
    }
コード例 #4
0
    void Start () {
        // Find is not optimal
        firstPerson_View = transform.Find ("FPS View").transform;
        charController = GetComponent<CharacterController> ();
        speed = walkSpeed;
        isMoving = false;

        rayDistance = charController.height * 0.5f + charController.radius;
        default_ControllerHeight = charController.height;
        default_CameraPosition = firstPerson_View.localPosition;

        playerAnimations = GetComponent<FPSPlayerAnimations> ();

        weaponManager.weapons[0].SetActive (true);
        currentWeapon = weaponManager.weapons[0].GetComponent<FPSWeapon> ();

        handsWeaponManager.weapons[0].SetActive (true);
        currentHandsWeapon = handsWeaponManager.weapons[0].GetComponent<FPSHandsWeapon> ();

        if (isLocalPlayer) {
            playerHolder.layer = LayerMask.NameToLayer ("Player");

            foreach (Transform child in playerHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Player");
            }

            for (int i = 0; i < weaponsFPS.Length; i++) {
                weaponsFPS[i].layer = LayerMask.NameToLayer ("Player");
            }

            weaponsHolder.layer = LayerMask.NameToLayer ("Enemy");

            foreach (Transform child in weaponsHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Enemy");
            }
        }

        if (!isLocalPlayer) {
            playerHolder.layer = LayerMask.NameToLayer ("Enemy");

            foreach (Transform child in playerHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Enemy");
            }

            for (int i = 0; i < weaponsFPS.Length; i++) {
                weaponsFPS[i].layer = LayerMask.NameToLayer ("Enemy");
            }

            weaponsHolder.layer = LayerMask.NameToLayer ("Player");

            foreach (Transform child in weaponsHolder.transform) {
                child.gameObject.layer = LayerMask.NameToLayer ("Player");
            }
        }

        if (!isLocalPlayer) {
            for (int i = 0; i < mouseLook.Length; i++) {
                mouseLook[i].enabled = false;
            }
        }

        // Deactivates all FPS Cameras
        mainCam = transform.Find ("FPS View").Find ("FPS Camera").GetComponent<Camera> ();
        mainCam.gameObject.SetActive (false);

        if (!isLocalPlayer) {
            for (int i = 0; i < playerRenderer1.materials.Length; i++) {
                //playerRenderer1.materials[i].color = playerColors[i];
                //playerRenderer2.materials[i].color = playerColors[i];
                //playerRenderer3.materials[i].color = playerColors[i];

                // Players on server are set to delta skin
                playerRenderer1.material = delta;
                playerRenderer2.material = delta;
                playerRenderer3.material = delta;
            }
        } else {
            // Local player is set to swat skin
            playerRenderer1.material = swat;
            playerRenderer2.material = swat;
            playerRenderer3.material = swat;
        }

    }
コード例 #5
0
ファイル: FPSController.cs プロジェクト: galaxymacos/FPS
    private void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            isReloading = false; // instant refresh the cooldown of gun
            if (!handsWeaponManager.weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponManager.weapons.Length; i++)
                {
                    handsWeaponManager.weapons[i].SetActive(false);
                }

                currentHandsWeapon = null;
                handsWeaponManager.weapons[0].SetActive(true);
                currentHandsWeapon = handsWeaponManager.weapons[0].GetComponent <FPSHandsWeapon>();
                if (_audioSource.clip != currentHandsWeapon.drawClip)
                {
                    _audioSource.clip = currentHandsWeapon.drawClip;
                }

                _audioSource.Play();
            }

            if (!weaponManager.weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < weaponManager.weapons.Length; i++)
                {
                    weaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                weaponManager.weapons[0].SetActive(true);
                currentWeapon = weaponManager.weapons[0].GetComponent <FPSWeapon>();
                playerAnimation.ChangeController(true);
            }
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            isReloading = false; // instant refresh the cooldown of gun

            if (!handsWeaponManager.weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponManager.weapons.Length; i++)
                {
                    handsWeaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                handsWeaponManager.weapons[1].SetActive(true);
                currentHandsWeapon = handsWeaponManager.weapons[1].GetComponent <FPSHandsWeapon>();
                playerAnimation.ChangeController(false);
                if (_audioSource.clip != currentHandsWeapon.drawClip)
                {
                    _audioSource.clip = currentHandsWeapon.drawClip;
                }

                _audioSource.Play();
            }

            if (!weaponManager.weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < weaponManager.weapons.Length; i++)
                {
                    weaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                weaponManager.weapons[1].SetActive(true);
                currentWeapon = weaponManager.weapons[1].GetComponent <FPSWeapon>();
                playerAnimation.ChangeController(true);
            }
        }

        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            isReloading = false; // instant refresh the cooldown of gun

            if (!handsWeaponManager.weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < handsWeaponManager.weapons.Length; i++)
                {
                    handsWeaponManager.weapons[i].SetActive(false);
                }

                currentHandsWeapon = null;
                handsWeaponManager.weapons[2].SetActive(true);
                currentHandsWeapon = handsWeaponManager.weapons[2].GetComponent <FPSHandsWeapon>();
                playerAnimation.ChangeController(false);
                if (_audioSource.clip != currentHandsWeapon.drawClip)
                {
                    _audioSource.clip = currentHandsWeapon.drawClip;
                }

                _audioSource.Play();
            }

            if (!weaponManager.weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < weaponManager.weapons.Length; i++)
                {
                    weaponManager.weapons[i].SetActive(false);
                }

                currentWeapon = null;
                weaponManager.weapons[2].SetActive(true);
                currentWeapon = weaponManager.weapons[2].GetComponent <FPSWeapon>();
                playerAnimation.ChangeController(false);
            }
        }
    }
コード例 #6
0
ファイル: FPScontroller.cs プロジェクト: gary23w/fps-game
    void Start()
    {
        firstPerson_view  = transform.Find("FPS VIEW").transform;
        charController    = GetComponent <CharacterController> ();
        speed             = walkSpeed;
        is_moving         = false;
        isShooting.value  = 1;
        reloadNoification = GameObject.Find("ReloadNotification");
        reloadNoification.GetComponent <Animator>().enabled = false;
        reloadNoification.transform.localScale = Vector3.zero;
        rayDistance = charController.height * 0.5f + charController.radius;
        default_controllerHeight = charController.height;
        default_CamPos           = firstPerson_view.localPosition;
        playerAnimations         = GetComponent <FPSPlayerAnimations>();
        weapon_Manager.weapons[0].SetActive(true);
        current_Weapon = weapon_Manager.weapons[0].GetComponent <FPSWeapon>();
        handsWeapon_Manager.weapons[0].SetActive(true);
        if (isFpsActive)
        {
            current_hands_Weapon = handsWeapon_Manager.weapons[0].GetComponent <FPSHandsWeapon> ();
        }



        // if(isLocalPlayer) {
        //     playerHolder.layer = LayerMask.NameToLayer ("Player");

        //     foreach (Transform child in playerHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer ("Player");
        //     }
        //     for(int i = 0; i < weapons_FPS.Length; i++) {
        //         weapons_FPS [i].layer = LayerMask.NameToLayer("Player");
        //     }
        //     weaponsHolder.layer = LayerMask.NameToLayer ("Enemy");

        //     foreach(Transform child in weaponsHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer("Enemy");
        //     }

        // }
        // if(!isLocalPlayer) {
        //     playerHolder.layer = LayerMask.NameToLayer ("Enemy");

        //     foreach (Transform child in playerHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer ("Enemy");
        //     }
        //     for(int i = 0; i < weapons_FPS.Length; i++) {
        //         weapons_FPS [i].layer = LayerMask.NameToLayer("Enemy");
        //     }
        //     weaponsHolder.layer = LayerMask.NameToLayer ("Player");

        //     foreach(Transform child in weaponsHolder.transform) {
        //         child.gameObject.layer = LayerMask.NameToLayer("Player");
        //     }
        // }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLooks.Length; i++)
            {
                mouseLooks[i].enabled = false;
            }
        }
        mainCam = transform.Find("FPS VIEW").Find("FPS Camera").GetComponent <Camera>();
        mainCam.gameObject.SetActive(false);

        if (!isLocalPlayer)
        {
            tag = "Enemy";
            for (int i = 0; i < playererRendered.materials.Length; i++)
            {
                /// RANDOM SKIN IN FUTURE;
            }
        }
    }
コード例 #7
0
ファイル: FPScontroller.cs プロジェクト: gary23w/fps-game
    void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            ak47Back.SetActive(true);
            m4a1Back.SetActive(true);
            ammo.value = PlayerPrefs.GetInt("DEAGLE");

            if (!handsWeapon_Manager.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons[i].SetActive(false);
                }
                current_hands_Weapon = null;
                handsWeapon_Manager.weapons[0].SetActive(true);
                if (isFpsActive)
                {
                    current_hands_Weapon = handsWeapon_Manager.weapons[0].GetComponent <FPSHandsWeapon>();
                }
            }
            if (!weapon_Manager.weapons [0].activeInHierarchy)
            {
                for (int i = 0; i < weapon_Manager.weapons.Length; i++)
                {
                    weapon_Manager.weapons[i].SetActive(false);
                }

                current_Weapon = null;
                weapon_Manager.weapons[0].SetActive(true);
                current_Weapon = weapon_Manager.weapons[0].GetComponent <FPSWeapon> ();
                playerAnimations.ChangeController(true);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            ak47Back.SetActive(false);
            m4a1Back.SetActive(true);
            ammo.value = PlayerPrefs.GetInt("AK47");
            if (!handsWeapon_Manager.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons[i].SetActive(false);
                }
                current_hands_Weapon = null;
                handsWeapon_Manager.weapons[1].SetActive(true);
                if (isFpsActive)
                {
                    current_hands_Weapon = handsWeapon_Manager.weapons[1].GetComponent <FPSHandsWeapon>();
                }
            }
            if (!weapon_Manager.weapons [1].activeInHierarchy)
            {
                for (int i = 0; i < weapon_Manager.weapons.Length; i++)
                {
                    weapon_Manager.weapons[i].SetActive(false);
                }

                current_Weapon = null;
                weapon_Manager.weapons[1].SetActive(true);
                current_Weapon = weapon_Manager.weapons[1].GetComponent <FPSWeapon> ();
                playerAnimations.ChangeController(false);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            ak47Back.SetActive(true);
            m4a1Back.SetActive(false);
            ammo.value = PlayerPrefs.GetInt("M4A1");

            if (!handsWeapon_Manager.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < handsWeapon_Manager.weapons.Length; i++)
                {
                    handsWeapon_Manager.weapons[i].SetActive(false);
                }
                current_hands_Weapon = null;
                handsWeapon_Manager.weapons[2].SetActive(true);
                if (isFpsActive)
                {
                    current_hands_Weapon = handsWeapon_Manager.weapons[2].GetComponent <FPSHandsWeapon>();
                }
            }
            if (!weapon_Manager.weapons [2].activeInHierarchy)
            {
                for (int i = 0; i < weapon_Manager.weapons.Length; i++)
                {
                    weapon_Manager.weapons[i].SetActive(false);
                }
                current_Weapon = null;
                weapon_Manager.weapons[2].SetActive(true);
                current_Weapon = weapon_Manager.weapons[2].GetComponent <FPSWeapon> ();
                playerAnimations.ChangeController(false);
            }
        }
    }
コード例 #8
0
    // Use this for initialization
    void Start()
    {
        this.m_firstPersonView = this.transform.Find("FPS View").transform;
        //transform.Find會從自己的遊戲物件子列表中去尋找對應的物件,這個方法會比GameObject.find還要快
        this.m_charController = this.GetComponent <CharacterController>();
        this.m_fSpeed         = this.m_fWalkSpeed;
        this.m_bIsMoving      = false;

        this.m_fRayDis = this.m_charController.height + this.m_charController.radius;
        print("射線距離 " + this.m_fRayDis);
        this.m_fDefaultControllerHeight = this.m_charController.height;
        this.m_defaulCamPos             = this.m_firstPersonView.localPosition;
        this.m_playerAnim = this.GetComponent <FPSPlayerAnim>();

        this.m_weaponManager.Weapons[0].SetActive(true);
        this.m_currentWeapon = this.m_weaponManager.Weapons[0].GetComponent <FPSWeapon>();

        this.m_handsWeaponManager.Weapons[0].SetActive(true);
        this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[0].GetComponent <FPSHandsWeapon>();

        if (this.isLocalPlayer)
        {
            this.m_playerHolder.layer = LayerMask.NameToLayer("Player");
            foreach (Transform child in m_playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
            for (int i = 0; i < m_arrWeaponsFPS.Length; i++)
            {
                m_arrWeaponsFPS[i].layer = LayerMask.NameToLayer("Player");
            }
            m_weaponsHolder.layer = LayerMask.NameToLayer("Enemy");
            foreach (Transform child in m_weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
        }
        //if (!this.isLocalPlayer)
        else
        {
            this.m_playerHolder.layer = LayerMask.NameToLayer("Enemy");
            foreach (Transform child in m_playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
            for (int i = 0; i < m_arrWeaponsFPS.Length; i++)
            {
                m_arrWeaponsFPS[i].layer = LayerMask.NameToLayer("Enemy");
            }
            m_weaponsHolder.layer = LayerMask.NameToLayer("Player");
            foreach (Transform child in m_weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
            for (int i = 0; i < m_arrMouseLook.Length; i++)
            {
                m_arrMouseLook[i].enabled = false;
            }
            this.m_mainCam.gameObject.SetActive(false);
        }
    }
コード例 #9
0
    void SelectWeapon()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            if (!m_handsWeaponManager.Weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < m_handsWeaponManager.Weapons.Count; i++)
                {
                    this.m_handsWeaponManager.Weapons[i].SetActive(false);
                }
                this.m_curHandsWeapon = null;
                this.m_handsWeaponManager.Weapons[0].SetActive(true);
                this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[0].GetComponent <FPSHandsWeapon>();
            }

            if (!this.m_weaponManager.Weapons[0].activeInHierarchy)
            {
                for (int i = 0; i < this.m_weaponManager.Weapons.Count; i++)
                {
                    this.m_weaponManager.Weapons[i].SetActive(false);
                }
                this.m_currentWeapon = null;
                this.m_weaponManager.Weapons[0].SetActive(true);
                this.m_currentWeapon = this.m_weaponManager.Weapons[0].GetComponent <FPSWeapon>();
                this.m_playerAnim.ChangeController(true);
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (!m_handsWeaponManager.Weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < m_handsWeaponManager.Weapons.Count; i++)
                {
                    this.m_handsWeaponManager.Weapons[i].SetActive(false);
                }
                this.m_curHandsWeapon = null;
                this.m_handsWeaponManager.Weapons[1].SetActive(true);
                this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[1].GetComponent <FPSHandsWeapon>();
            }

            if (!this.m_weaponManager.Weapons[1].activeInHierarchy)
            {
                for (int i = 0; i < this.m_weaponManager.Weapons.Count; i++)
                {
                    this.m_weaponManager.Weapons[i].SetActive(false);
                }
                this.m_currentWeapon = null;
                this.m_weaponManager.Weapons[1].SetActive(true);
                this.m_currentWeapon = this.m_weaponManager.Weapons[1].GetComponent <FPSWeapon>();
                this.m_playerAnim.ChangeController(false);
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            if (!m_handsWeaponManager.Weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < m_handsWeaponManager.Weapons.Count; i++)
                {
                    this.m_handsWeaponManager.Weapons[i].SetActive(false);
                }
                this.m_curHandsWeapon = null;
                this.m_handsWeaponManager.Weapons[2].SetActive(true);
                this.m_curHandsWeapon = this.m_handsWeaponManager.Weapons[2].GetComponent <FPSHandsWeapon>();
            }

            if (!this.m_weaponManager.Weapons[2].activeInHierarchy)
            {
                for (int i = 0; i < this.m_weaponManager.Weapons.Count; i++)
                {
                    this.m_weaponManager.Weapons[i].SetActive(false);
                }
                this.m_currentWeapon = null;
                this.m_weaponManager.Weapons[2].SetActive(true);
                this.m_currentWeapon = this.m_weaponManager.Weapons[2].GetComponent <FPSWeapon>();
                this.m_playerAnim.ChangeController(false);
            }
        }
    }
コード例 #10
0
    // Use this for initialization
    void Start()
    {
        firstPersonView = transform.Find("FPS View").transform;

        charController = GetComponent <CharacterController> ();

        speed = walkSpeed;

        isMoving = false;

        rayDistance = charController.height * 0.5f + charController.radius;

        defaultControllerHeight = charController.height;

        defaultCamPos = firstPersonView.localPosition;

        playerAnimations = GetComponent <FPSPlayerAnimations> ();

        weaponsManager.weapons [0].SetActive(true);

        currentWeapon = weaponsManager.weapons [0].GetComponent <FPSWeapon> ();

        handsWeaponsManager.weapons [0].SetActive(true);

        currentHandsWeapon = handsWeaponsManager.weapons [0].GetComponent <FPSHandsWeapon> ();

        // Change the view based on whether or not the current player
        // is a local player or a remote player
        if (isLocalPlayer)
        {
            playerHolder.layer = LayerMask.NameToLayer("Player");

            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }

            for (int i = 0; i < weaponsFPS.Length; i++)
            {
                weaponsFPS [i].layer = LayerMask.NameToLayer("Player");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Enemy");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }
        }
        else
        {
            playerHolder.layer = LayerMask.NameToLayer("Enemy");

            foreach (Transform child in playerHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Enemy");
            }

            for (int i = 0; i < weaponsFPS.Length; i++)
            {
                weaponsFPS [i].layer = LayerMask.NameToLayer("Enemy");
            }

            weaponsHolder.layer = LayerMask.NameToLayer("Player");

            foreach (Transform child in weaponsHolder.transform)
            {
                child.gameObject.layer = LayerMask.NameToLayer("Player");
            }
        }

        if (!isLocalPlayer)
        {
            for (int i = 0; i < mouseLook.Length; i++)
            {
                mouseLook [i].enabled = false;
            }
        }

        mainCam = transform.Find("FPS View").Find("FPS Camera").GetComponent <Camera> ();
        mainCam.gameObject.SetActive(false);
    }