コード例 #1
0
ファイル: RayCastScript.cs プロジェクト: ivitz/DarkWorld-PC-
    void Update()
    {
        //Debug.Log (IsGrounded());

        /*
         * if (fpsController.m_CharacterController.velocity.y < -20)
         * {
         *  Debug.Log(fpsController.m_CharacterController.velocity);
         * }
         */
        /*
         * foreach (Collider coll in Overlap()) {
         *      Debug.Log (coll.name);
         * }
         */


        /*
         * if (PlayerConversations.conversationActive == true || playerStats.readingNote || playerStats.isPause) {
         *      timeOfJump = Time.time;
         * }
         */
        //fall damage (get the time of jump and the land and calculate if it is big


        //===========================================FALL DAMAGE
        if (enableFallDamage)
        {
            currentSpeed = fpsController.m_CharacterController.velocity.y;


            if (currentSpeed >= -1 && prevFrameSpeed <= -40)
            {
                //Debug.Log ("Cyrrent speed: " + currentSpeed);
                //Debug.Log ("Previous speed: " + prevFrameSpeed);
                Debug.Log("Cyrrent speed: " + currentSpeed);
                Debug.Log("Previous speed: " + prevFrameSpeed);

                //playerAudioAttack.Play ();

                DamagePlayer();

                playerStats.playerHP += prevFrameSpeed * 1.8f;
                //Debug.Log ("apply fall damage" + prevFrameSpeed * 1.4f);
            }

            prevFrameSpeed = fpsController.m_CharacterController.velocity.y;
        }
        //===========================================FALL DAMAGE



        //input
        lmbPressed = false;
        rmbPressed = false;
        fPressed   = false;
        qPressed   = false;
        if (Input.GetButton("Fire1"))
        {
            if (!PlayerConversations.conversationActive && !SavePlayerStats.disableControlls)
            {
                lmbPressed = true;
            }
        }
        if (Input.GetButton("PickUp"))
        {
            if (!PlayerConversations.conversationActive && !SavePlayerStats.disableControlls)
            {
                fPressed = true;
            }
        }

        /*
         *      if (Input.GetKey ("f")) {
         *              fPressed = true;
         *      }
         */
        if (Input.GetButton("Fire2"))
        {
            if (!PlayerConversations.conversationActive && !SavePlayerStats.disableControlls)
            {
                rmbPressed = true;
            }
        }
        if (Input.GetKey("q"))
        {
            if (!PlayerConversations.conversationActive && !SavePlayerStats.disableControlls)
            {
                qPressed = true;
            }
        }
        if (pickUpInHands && Time.time >= pickUpNextTime)
        {
            if (Input.GetButton("PickUp"))
            {
                pickUp.DropObject(pickUpObject);
                pickUpNextTime = Time.time + 1;
                pickUpInHands  = false;
            }
        }

        if (Input.GetButtonDown("ChangeWeapon"))    //change ranged weapon
        {
            InventoryScript.SelectNextWeaponRanged();
        }

        if (Input.GetKeyDown("p"))
        {
            InventoryScript.SelectBestWeapon();
        }

        /*
         *      if (Input.GetKeyDown ("o")) {
         *              SceneManager.LoadScene ("World01");
         *      }
         *      if (Input.GetKeyDown ("l")) {
         *              SceneManager.LoadScene ("World02(Forest)");
         *      }
         */
        //input


        if (!isDead)
        {
            //DEATH
            if (Mathf.Round(playerStats.playerHP) <= 0)
            {
                PlayerDies();
            }
            //DEATH

            mainText.text = "";
            if (playerStats.playerEXP > playerStats.playerCurrentEXP)
            {
                playerStats.StatsUpdate();
            }


            //ranged attack
            if (playerStats.totalAmmo >= playerStats.ammoConsume)
            {
                //reload the gun
                if (Time.time > reloadRange && reloadedAmmo == false)
                {
                    reloadedAmmo         = true;
                    playerStats.currAmmo = playerStats.totalWeaponAmmo;
                }

                //press R to reload (makes currammo 0 so the reload happens)
                if (Input.GetKeyDown(KeyCode.R))
                {
                    playerStats.currAmmo = 0;
                }
                if (playerStats.currAmmo <= 0 && reloadedAmmo == true && playerStats.totalWeaponAmmo > 0)
                {
                    reloadedAmmo = false;
                    reloadRange  = Time.time + playerStats.reloadTime;
                    reloadAudioSource.Play();                                                                           //play reload sound
                    fpsWeapon.ReloadRecoil();
                }
                if (rmbPressed == true)                                                                                                         //check if pressed RMB

                {
                    if (Time.time > reloadRange && reloadedAmmo == true)
                    {
                        if (playerStats.currAmmo > 0)
                        {
                            reloadRange = Time.time + playerStats.rangedAttackSpeed;
                            Attack(true);
                        }
                    }
                }
            }

            //Interract
            if (lmbPressed == true)
            {
                if (!playerStats.isPause)
                {
                    Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, 15.0f))
                    {
                        //Debug.Log (hit.collider.name);
                        if (Time.time > newHit)                           //&& hit.collider.isTrigger == false) { //attack enemy!
                        {
                            newHit = Time.time + playerStats.playerHitRate;
                            Attack(false);                             //ray, hit, false);
                        }

                        //dont pickup endlessly! use newHit time.
                        if (newPickup < Time.time)
                        {
                            newPickup = Time.time + 0.3f;
                            //picking up weapons
                            if (hit.collider.tag == "PickUpObjects")
                            {
                                hit.collider.GetComponent <WeaponScript> ().PickUpWeapon();
                                saveManager.AddID(hit.collider.GetComponent <WeaponScript> ().iD);
                            }
                            if (hit.collider.tag == "Ammo")                               //when picking up ammo
                            {
                                playerStats.AmmoPickUp(hit.collider.GetComponent <Ammo> ().ammoAmount, hit.collider.gameObject);
                            }
                            if (hit.collider.tag == "MonsterSoul")                               //when picking up monster soul
                            {
                                playerStats.SoulPickUp(hit.collider.GetComponent <MonsterSoul> ().soulAmount, hit.collider.GetComponent <MonsterSoul> ().soulEXP, hit.collider.gameObject);
                            }
                            if (hit.collider.tag == "WeaponUpgrade")                               //when picking up ammo
                            {
                                playerStats.UpgradePickup(hit.collider.GetComponent <WeaponUpgradeItem> ().upgradeAmount, hit.collider.gameObject);
                            }
                            //when picking up armor
                            if (hit.collider.tag == "Armor")
                            {
                                playerStats.ArmorPickUp(hit.collider.GetComponent <Armor> ().armorAmount, hit.collider.gameObject);
                            }
                            if (hit.collider.tag == "Note")                               //when picking up note
                            {
                                if (!playerStats.readingNote)
                                {
                                    playerStats.NotePickUp(hit.collider.GetComponent <Notes> ().noteText, hit.collider.gameObject);
                                }
                            }
                            if (hit.collider.tag == "Sign")
                            {
                                playerStats.ReadSign(hit.collider.GetComponent <PostSign>().signText);
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (secondConvo && secondConvoStart && !DialogueManager.IsConversationActive)
        {
            if (playerStats != null && !playerStats.isPause && !playerStats.readingNote)
            {
                if (Input.GetButtonDown("Fire1"))
                {
                    Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, 10f))
                    {
                        if (playerStats.playerHP > 0)
                        {
                            if (hit.collider.gameObject == gameObject)
                            {
                                DialogueManager.StartConversation(secondConvoName, player.transform, transform);
                            }
                        }
                    }
                }
            }
        }

        if (!convoOnce && !DialogueManager.IsConversationActive)
        {
            if (playerStats != null && !playerStats.isPause && !playerStats.readingNote)
            {
                if (startThisConvo)
                {
                    DialogueManager.StartConversation(convoName, player.transform, transform);
                    startThisConvo = false;
                }

                if (Input.GetButtonDown("Fire1"))
                {
                    Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, 10f))
                    {
                        if (hit.collider.gameObject == gameObject)
                        {
                            if (playerStats.playerHP > 0)
                            {
                                if (once)
                                {
                                    convoOnce = true;
                                }
                                if (secondConvo)
                                {
                                    secondConvoStart = true;
                                }
                                DialogueManager.StartConversation(convoName, player.transform, transform);

                                if (once)
                                {
                                    saveManager.AddID(iD);
                                    //Debug.Log("convo added " + iD);
                                }
                            }
                        }
                    }
                }
            }
        }
    }