コード例 #1
0
    /**
     * Proceed shoot into mouse cursour direction!
     * Check for cooldown; then intantiate and setup rocket.
     * @param	mousePos	Current position of the mouse cursour.
     */
    private void Shoot(Vector3 mousePos)
    {
        // check if we are off cooldown
        if ((Time.time > lastShotTimestamp + cooldown) ||
            (rageCounter > 0 && Time.time > lastShotTimestamp + rageCooldown))
        {
            animator.SetBool("Shot", true);

            // animate cooldown
            crosshair.StartAnimation();

            // calculate normalized direction
            Vector3 direction = mousePos - this.transform.position;
            direction.y = 0;
            direction.Normalize();

            // set start position of the projectile
            Vector3 pos = rocketStart.transform.position;

            // instatiate VFX
            PhotonNetwork.Instantiate(muzzleFlash.name,
                                      pos,
                                      Quaternion.LookRotation(direction), 0);
            // instatiate projectile
            GameObject handle = PhotonNetwork.Instantiate(projectile.name,
                                                          pos,
                                                          Quaternion.LookRotation(direction), 0);
            handle.GetPhotonView().RPC("InstatiateTimeStamp", PhotonTargets.AllBuffered, (float)PhotonNetwork.time);
            handle.GetPhotonView().RPC("SetTarget", PhotonTargets.AllBuffered, mousePos);

            // save information about shoot
            lastShotTimestamp = Time.time;

            // decrease rage counter
            // change crosshair animation speed according to next cooldown


            if (rageCounter > 0)
            {
                rageCounter--;
                crosshair.SetAnimationTime(rageCooldown);
            }
            else
            {
                crosshair.SetAnimationTime(cooldown);
            }
        }
    }