コード例 #1
0
        //-------------------------------------------------
        public void ArrowInPosition()
        {
            DoHandednessCheck();

            if (nockSound != null)
            {
                nockSound.Play();
            }
        }
コード例 #2
0
 public override void Fire(Vector3 speedAndDir)
 {
     base.Fire(speedAndDir);
     Animator.SetBool(_hashRotate, true);
     if (ThrowSound != null)
     {
         ThrowSound.Play();
     }
 }
コード例 #3
0
ファイル: PistolShootController.cs プロジェクト: Bmak/VRProto
        public void ReloadWeapon()
        {
            if (_currentAmmo == MAX_AMMO)
            {
                return;
            }

            reloadSound.Play();
            _currentAmmo = MAX_AMMO;
            UpdateAmmo();
        }
コード例 #4
0
ファイル: BalloonMaker.cs プロジェクト: teunw/Assignment-VR
    public void StartMakingBalloon()
    {
        BalloonSize         = BalloonStartSize;
        this.CurrentBalloon = Instantiate(BalloonPrefab, BalloonParent.transform);
        this.CurrentBalloon.transform.position = this.transform.position + (this.transform.up * HeightOffset);

        this.CurrentBalloon.gameObject.GetComponent <Renderer>().material.color = PossibleColors.GetRandomElement();

        var fixedJoint = this.CurrentBalloon.gameObject.AddComponent <FixedJoint>();

        fixedJoint.connectedBody = this.GetComponent <Rigidbody>();
        InflateClip.Play();
    }
コード例 #5
0
        //-------------------------------------------------
        public void ArrowReleased()
        {
            nocked = false;
            hand.HoverUnlock(GetComponent <VRTRIXInteractable>());
            hand.otherHand.HoverUnlock(arrowHand.GetComponent <VRTRIXInteractable>());

            if (releaseSound != null)
            {
                releaseSound.Play();
            }

            this.StartCoroutine(this.ResetDrawAnim());
        }
コード例 #6
0
        //-------------------------------------------------
        public void StartNock(VRTRIXGloveArrowHand currentArrowHand)
        {
            arrowHand = currentArrowHand;
            hand.HoverLock(GetComponent <VRTRIXInteractable>());
            nocked                = true;
            nockLerpStartTime     = Time.time;
            nockLerpStartRotation = pivotTransform.rotation;

            // Sound of arrow sliding on nock as it's being pulled back
            arrowSlideSound.Play();

            // Decide which hand we're drawing with and lerp to the correct side
            DoHandednessCheck();
        }
コード例 #7
0
 public void GetHit(ColliderPart partType, int points, float damage, Vector3 position)
 {
     if (_dead)
     {
         return;
     }
     hp -= damage;
     if (ScoreController.Instance != null)
     {
         ScoreController.Instance.AddScore(points, transform);
     }
     if (hp <= 0)
     {
         Vector3 direction = position - transform.position;
         float   angle     = Vector3.Angle(transform.forward, direction);
         direction = Quaternion.AngleAxis(angle, Vector3.up) * direction;
         _deathSound.Play();
         _deathParticles.Play();
         _animator.SetFloat("xDeath", direction.x);
         _animator.SetFloat("zDeath", direction.z);
         _animator.SetTrigger("Death");
         StartCoroutine(Die(position));
         return;
     }
     else if (partType == ColliderPart.Leg)
     {
         basicSpeed /= 2;
         chaseSpeed /= 2;
         _hurtSound.Play();
         //add anim
     }
     else
     {
         _animator.SetTrigger("Impact");
         _hurtSound.Play();
     }
 }
コード例 #8
0
ファイル: Bullet.cs プロジェクト: Bmak/VRProto
    //-------------------------------------------------
    public void BulletReleased(Transform weapon)
    {
        _weapon  = weapon;
        inFlight = true;

        airReleaseSound.Play();

        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.right, out hit))
        {
            SpawnParticles(hitEffect, hit.point);

            Transform t = hit.transform;
            while (t.parent != null)
            {
                var z = t.parent.GetComponent <EnemyController>();
                if (z != null)
                {
                    z.OnDamage();
                    var rb = hit.rigidbody;
                    rb.AddForce(-hit.normal * 100f, ForceMode.Impulse);

                    hitTargetSound.Play();

                    break;
                }
                t = t.parent.transform;
            }
            //bulletView.SetActive(false);
            Destroy(gameObject, 2f);
            Physics.IgnoreCollision(arrowHeadRB, hit.collider);
            return;
        }

        Destroy(gameObject, 10);
    }
コード例 #9
0
        //-------------------------------------------------
        public GameObject SpawnBalloon(Balloon.BalloonColor color = Balloon.BalloonColor.Red)
        {
            if (balloonPrefab == null)
            {
                return(null);
            }
            GameObject balloon = Instantiate(balloonPrefab, transform.position, transform.rotation) as GameObject;

            balloon.transform.localScale = new Vector3(scale, scale, scale);
            if (attachBalloon)
            {
                balloon.transform.parent = transform;
            }

            if (sendSpawnMessageToParent)
            {
                if (transform.parent != null)
                {
                    transform.parent.SendMessage("OnBalloonSpawned", balloon, SendMessageOptions.DontRequireReceiver);
                }
            }

            if (playSounds)
            {
                if (inflateSound != null)
                {
                    inflateSound.Play();
                }
                if (stretchSound != null)
                {
                    stretchSound.Play();
                }
            }
            balloon.GetComponentInChildren <Balloon>().SetColor(color);
            if (spawnDirectionTransform != null)
            {
                balloon.GetComponentInChildren <Rigidbody>().AddForce(spawnDirectionTransform.forward * spawnForce);
            }

            return(balloon);
        }
コード例 #10
0
 public void AddScore(int adding, Transform location)
 {
     _isComboing = true;
     _comboTimer = ComboDuration;
     _comboCount++;
     adding += _comboCount * 100;
     _comboCount++;
     _score += adding;
     if (ComboSound && _comboCount >= 8)
     {
         ComboSound.Play();
     }
     if (ScoreDisplay)
     {
         ScoreDisplay.text = _score.ToString();
     }
     if (ComboDisplay)
     {
         ComboDisplay.text = "x" + _comboCount.ToString();
     }
 }
コード例 #11
0
    private void OnCollisionEnter(Collision collision)
    {
        print("on collision enter: " + collision.transform.tag);

        if (collision.transform.tag == "Ax")
        {
            SoundPlayOneshot soundPlayOneshot = collision.transform.GetComponent <SoundPlayOneshot>();
            if (soundPlayOneshot != null)
            {
                soundPlayOneshot.Play();
            }
            else
            {
                Debug.LogError("SoundPlayOneshot component not found on axe.");
            }

            GameObject woodchipInstance = Instantiate(woodChipPrefab);
            woodchipInstance.transform.position = collision.contacts[0].point;

            chopCount++;

            if (chopCount > 2)
            {
                // Spawn logs and delete this.
                for (int i = 0; i < 3; i++)
                {
                    GameObject logInstance = Instantiate(logPrefab);
                    logInstance.transform.position = transform.position + new Vector3(Random.Range(-1f, 1f), Random.Range(0f, 0.5f), Random.Range(-1f, 1f));
                }

                GameObject smokeInstance = Instantiate(smokePrefab);
                smokeInstance.transform.position = transform.position;

                Destroy(gameObject);
            }
        }
    }
コード例 #12
0
ファイル: Arrow.cs プロジェクト: nhcarter123/WorldWizards
        //-------------------------------------------------
        public void ArrowReleased(float inputVelocity)
        {
            inFlight = true;
            released = true;

            airReleaseSound.Play();

            if (glintParticle != null)
            {
                glintParticle.Play();
            }

            if (gameObject.GetComponentInChildren <FireSource>().isBurning)
            {
                fireReleaseSound.Play();
            }

            // Check if arrow is shot inside or too close to an object
            RaycastHit[] hits = Physics.SphereCastAll(transform.position, 0.01f, transform.forward, 0.80f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore);
            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.gameObject != gameObject && hit.collider.gameObject != arrowHeadRB.gameObject && hit.collider != Player.instance.headCollider)
                {
                    Destroy(gameObject);
                    return;
                }
            }

            travelledFrames  = 0;
            prevPosition     = transform.position;
            prevRotation     = transform.rotation;
            prevHeadPosition = arrowHeadRB.transform.position;
            prevVelocity     = GetComponent <Rigidbody>().velocity;

            Destroy(gameObject, 30);
        }
コード例 #13
0
ファイル: ArrowHand.cs プロジェクト: nhcarter123/WorldWizards
        //-------------------------------------------------
        private void HandAttachedUpdate(Hand hand)
        {
            if (bow == null)
            {
                FindBow();
            }

            if (bow == null)
            {
                return;
            }

            if (allowArrowSpawn && (currentArrow == null))                 // If we're allowed to have an active arrow in hand but don't yet, spawn one
            {
                currentArrow = InstantiateArrow();
                arrowSpawnSound.Play();
            }

            float distanceToNockPosition = Vector3.Distance(transform.parent.position, bow.nockTransform.position);

            // If there's an arrow spawned in the hand and it's not nocked yet
            if (!nocked)
            {
                // If we're close enough to nock position that we want to start arrow rotation lerp, do so
                if (distanceToNockPosition < rotationLerpThreshold)
                {
                    float lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1);

                    arrowNockTransform.rotation = Quaternion.Lerp(arrowNockTransform.parent.rotation, bow.nockRestTransform.rotation, lerp);
                }
                else                 // Not close enough for rotation lerp, reset rotation
                {
                    arrowNockTransform.localRotation = Quaternion.identity;
                }

                // If we're close enough to the nock position that we want to start arrow position lerp, do so
                if (distanceToNockPosition < positionLerpThreshold)
                {
                    float posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1);

                    posLerp = Mathf.Clamp(posLerp, 0f, 1f);

                    arrowNockTransform.position = Vector3.Lerp(arrowNockTransform.parent.position, bow.nockRestTransform.position, posLerp);
                }
                else                 // Not close enough for position lerp, reset position
                {
                    arrowNockTransform.position = arrowNockTransform.parent.position;
                }


                // Give a haptic tick when lerp is visually complete
                if (distanceToNockPosition < lerpCompleteDistance)
                {
                    if (!arrowLerpComplete)
                    {
                        arrowLerpComplete = true;
                        hand.controller.TriggerHapticPulse(500);
                    }
                }
                else
                {
                    if (arrowLerpComplete)
                    {
                        arrowLerpComplete = false;
                    }
                }

                // Allow nocking the arrow when controller is close enough
                if (distanceToNockPosition < nockDistance)
                {
                    if (!inNockRange)
                    {
                        inNockRange = true;
                        bow.ArrowInPosition();
                    }
                }
                else
                {
                    if (inNockRange)
                    {
                        inNockRange = false;
                    }
                }

                // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock
                if ((distanceToNockPosition < nockDistance) && hand.controller.GetPress(SteamVR_Controller.ButtonMask.Trigger) && !nocked)
                {
                    if (currentArrow == null)
                    {
                        currentArrow = InstantiateArrow();
                    }

                    nocked = true;
                    bow.StartNock(this);
                    hand.HoverLock(GetComponent <Interactable>());
                    allowTeleport.teleportAllowed = false;
                    currentArrow.transform.parent = bow.nockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    Util.ResetTransform(arrowNockTransform);
                }
            }


            // If arrow is nocked, and we release the trigger
            if (nocked && (!hand.controller.GetPress(SteamVR_Controller.ButtonMask.Trigger) || hand.controller.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)))
            {
                if (bow.pulled)                   // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand
                {
                    FireArrow();
                }
                else
                {
                    arrowNockTransform.rotation   = currentArrow.transform.rotation;
                    currentArrow.transform.parent = arrowNockTransform;
                    Util.ResetTransform(currentArrow.transform);
                    nocked = false;
                    bow.ReleaseNock();
                    hand.HoverUnlock(GetComponent <Interactable>());
                    allowTeleport.teleportAllowed = true;
                }

                bow.StartRotationLerp();                 // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation
            }
        }
コード例 #14
0
ファイル: Arrow.cs プロジェクト: nhcarter123/WorldWizards
        //-------------------------------------------------
        private void StickInTarget(Collision collision, bool bSkipRayCast)
        {
            Vector3 prevForward = prevRotation * Vector3.forward;

            // Only stick in target if the collider is front of the arrow head
            if (!bSkipRayCast)
            {
                RaycastHit[] hitInfo;
                hitInfo = Physics.RaycastAll(prevHeadPosition - prevVelocity * Time.deltaTime, prevForward, prevVelocity.magnitude * Time.deltaTime * 2.0f);
                bool properHit = false;
                for (int i = 0; i < hitInfo.Length; ++i)
                {
                    RaycastHit hit = hitInfo[i];

                    if (hit.collider == collision.collider)
                    {
                        properHit = true;
                        break;
                    }
                }

                if (!properHit)
                {
                    return;
                }
            }

            Destroy(glintParticle);

            inFlight = false;

            shaftRB.velocity        = Vector3.zero;
            shaftRB.angularVelocity = Vector3.zero;
            shaftRB.isKinematic     = true;
            shaftRB.useGravity      = false;
            shaftRB.transform.GetComponent <BoxCollider>().enabled = false;

            arrowHeadRB.velocity        = Vector3.zero;
            arrowHeadRB.angularVelocity = Vector3.zero;
            arrowHeadRB.isKinematic     = true;
            arrowHeadRB.useGravity      = false;
            arrowHeadRB.transform.GetComponent <BoxCollider>().enabled = false;

            hitTargetSound.Play();


            // If the hit item has a parent, dock an empty object to that
            // this fixes an issue with scaling hierarchy. I suspect this is not sustainable for a large object / scaling hierarchy.
            scaleParentObject = new GameObject("Arrow Scale SetParent");
            Transform parentTransform = collision.collider.transform;

            // Don't do this for weebles because of how it has a fixed joint
            ExplosionWobble wobble = collision.collider.gameObject.GetComponent <ExplosionWobble>();

            if (!wobble)
            {
                if (parentTransform.parent)
                {
                    parentTransform = parentTransform.parent;
                }
            }

            scaleParentObject.transform.parent = parentTransform;

            // Move the arrow to the place on the target collider we were expecting to hit prior to the impact itself knocking it around
            transform.parent   = scaleParentObject.transform;
            transform.rotation = prevRotation;
            transform.position = prevPosition;
            transform.position = collision.contacts[0].point - transform.forward * (0.75f - (Util.RemapNumberClamped(prevVelocity.magnitude, 0f, 10f, 0.0f, 0.1f) + Random.Range(0.0f, 0.05f)));
        }
コード例 #15
0
 public void PlayAirRelease()
 {
     airReleaseSound.Play();
 }