Example #1
0
    override public void FixedUpdate()
    {
        if (InHandLeft)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(true);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerLeft.transform.position;
            transform.rotation = HandControllerLeft.transform.rotation;
            HandControllerLeft.GetComponent <RobustController>().HoldableObject = this.gameObject;

            // play whoosh sound
            float WhooshDist = Vector3.Distance(PreviousPosition, transform.position);
            if (WhooshDist > 0.04f)
            {
                //if(AudioWhoosh.isPlaying == false) AudioWhoosh.PlayOneShot(WhooshSounds[(Random.Range(0,(WhooshSounds.Length-1)))]);
            }
        }
        if (InHandRight)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(true);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerRight.transform.position;
            transform.rotation = HandControllerRight.transform.rotation;
            HandControllerRight.GetComponent <RobustController>().HoldableObject = this.gameObject;

            // play whoosh sound
            float WhooshDist = Vector3.Distance(PreviousPosition, transform.position);
            if (WhooshDist > 0.04f)
            {
                //if(AudioWhoosh.isPlaying == false) AudioWhoosh.PlayOneShot(WhooshSounds[(Random.Range(0,(WhooshSounds.Length-1)))]);
            }
        }

        if (!InHandLeft && !InHandRight)
        {
            this.gameObject.layer = 0;             // change layer to Default for physics collisions
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            if (Dropped)
            {
                this.GetComponent <Rigidbody>().isKinematic = false;
                if (UseMomentum)
                {
                    transform.root.GetComponent <Rigidbody>().velocity        = Velocity;
                    transform.root.GetComponent <Rigidbody>().angularVelocity = AngularVelocity;
                }
                Dropped = false;
            }
        }

        if (!Audio.isPlaying && TurnedOn)
        {
            Audio.PlayOneShot(IdleSound);
        }

        Velocity         = (transform.position - PreviousPosition) * (1f / Time.deltaTime);
        AngularVelocity  = ((transform.rotation * Vector3.forward) - PreviousRotation) * (1f / Time.deltaTime);
        PreviousPosition = transform.position;
        PreviousRotation = (transform.rotation * Vector3.forward);
    }
Example #2
0
    override public void FixedUpdate()
    {
        if (FlameOn)
        {
            // does the gun have any ammo?
            if (Ammo > 0)
            {
                Ammo -= Time.deltaTime;
                if (!Audio.isPlaying)
                {
                    Audio.Play();
                }
                LightFire.GetComponent <Light>().enabled = true;
                Flames.SetActive(true);
                //Debug.Log("Flame On !");
                if (TriggerCollisionObject != null)
                {
                    if (TriggerCollisionObject.transform.root.tag == "Baddie")
                    {
                        //Debug.Log("hit baddie");
                        TriggerCollisionObject.transform.root.GetComponent <Baddie>().SendMessage("TakeDamage", DamagePerFrame);
                    }
                }
            }
            else
            {
                Audio.Pause();
                FlameOn = false;
                LightFire.GetComponent <Light>().enabled = false;
                Flames.SetActive(false);
            }
        }
        else
        {
            Audio.Pause();
            LightFire.GetComponent <Light>().enabled = false;
            Flames.SetActive(false);
        }

        if (InHandLeft && InHandRight)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(true);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(true);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            //GunRigidBody.GetComponent<Rigidbody>().isKinematic = true;
            //GunRigidBody.transform.localPosition = Vector3.zero;
            //GunRigidBody.transform.localRotation = Quaternion.identity;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerLeft.transform.position;

            //transform.rotation = HandControllerLeft.transform.rotation;
            Vector3 targetDir = HandControllerLeft.transform.position - HandControllerRight.transform.position;
            transform.rotation = Quaternion.LookRotation(targetDir);

            HandControllerRight.GetComponent <RobustController>().HoldableObject = this.gameObject;
            HandControllerLeft.GetComponent <RobustController>().HoldableObject  = this.gameObject;
        }

        if (!InHandLeft && !InHandRight)
        {
            this.gameObject.layer = 0;             // change layer to Default for physics collisions
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            if (Dropped)
            {
                this.GetComponent <Rigidbody>().isKinematic = false;
                //GunRigidBody.GetComponent<Rigidbody>().isKinematic = false;
                if (UseMomentum)
                {
                    transform.root.GetComponent <Rigidbody>().velocity        = Velocity;
                    transform.root.GetComponent <Rigidbody>().angularVelocity = AngularVelocity;
                }
                Dropped = false;
            }
        }

        if (InHandLeft && !InHandRight)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(true);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            //GunRigidBody.GetComponent<Rigidbody>().isKinematic = false;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerLeft.transform.position;
            transform.rotation = HandControllerLeft.transform.rotation;
            HandControllerLeft.GetComponent <RobustController>().HoldableObject = this.gameObject;
        }

        if (InHandRight && !InHandLeft)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(true);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            //GunRigidBody.GetComponent<Rigidbody>().isKinematic = false;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerRight.transform.position;
            transform.rotation = HandControllerRight.transform.rotation;
            HandControllerRight.GetComponent <RobustController>().HoldableObject = this.gameObject;
        }

        Velocity         = (transform.position - PreviousPosition) * (1f / Time.deltaTime);
        AngularVelocity  = ((transform.rotation * Vector3.forward) - PreviousRotation) * (1f / Time.deltaTime);
        PreviousPosition = transform.position;
        PreviousRotation = (transform.rotation * Vector3.forward);
    }
Example #3
0
    override public void FixedUpdate()
    {
        if (MuzzleFlash != null)
        {
            MuzzleFlash.SetActive(false);
        }
        if (FireGunStart)
        {
            FireGun();
            if (MuzzleFlash != null)
            {
                if (WeaponAnimationController.GetInteger("Ammo") > 0)
                {
                    MuzzleFlash.SetActive(true);
                }
            }
        }


        if (InHandLeft || InHandRight)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(true);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(true);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerLeft.transform.position;

            //transform.rotation = HandControllerLeft.transform.rotation;
            Vector3 targetDir = HandControllerLeft.transform.position - HandControllerRight.transform.position;
            transform.rotation = Quaternion.LookRotation(targetDir);

            HandControllerRight.GetComponent <RobustController>().HoldableObject = this.gameObject;
            HandControllerLeft.GetComponent <RobustController>().HoldableObject  = this.gameObject;
        }

        if (!InHandLeft && !InHandRight)
        {
            this.gameObject.layer = 0;             // change layer to Default for physics collisions
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            if (Dropped)
            {
                this.GetComponent <Rigidbody>().isKinematic = false;
                if (UseMomentum)
                {
                    transform.root.GetComponent <Rigidbody>().velocity        = Velocity;
                    transform.root.GetComponent <Rigidbody>().angularVelocity = AngularVelocity;
                }
                Dropped = false;
            }
        }

        Velocity         = (transform.position - PreviousPosition) * (1f / Time.deltaTime);
        AngularVelocity  = ((transform.rotation * Vector3.forward) - PreviousRotation) * (1f / Time.deltaTime);
        PreviousPosition = transform.position;
        PreviousRotation = (transform.rotation * Vector3.forward);
    }
Example #4
0
    override public void FixedUpdate()
    {
        if (InHandLeft)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(true);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerLeft.transform.position;
            transform.rotation = HandControllerLeft.transform.rotation;
            HandControllerLeft.GetComponent <RobustController>().HoldableObject = this.gameObject;
        }
        if (InHandRight)
        {
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(true);
            }
            this.GetComponent <Rigidbody>().isKinematic = true;
            this.gameObject.layer = 9;             // change layer to InHand for physics collisions
            // slave to controller
            transform.position = HandControllerRight.transform.position;
            transform.rotation = HandControllerRight.transform.rotation;
            HandControllerRight.GetComponent <RobustController>().HoldableObject = this.gameObject;
        }

        if (!InHandLeft && !InHandRight)
        {
            this.gameObject.layer = 0;             // change layer to Default for physics collisions
            if (LeftHandModel != null)
            {
                LeftHandModel.SetActive(false);
            }
            if (RightHandModel != null)
            {
                RightHandModel.SetActive(false);
            }
            if (Dropped)
            {
                this.GetComponent <Rigidbody>().isKinematic = false;
                if (UseMomentum)
                {
                    transform.root.GetComponent <Rigidbody>().velocity        = Velocity;
                    transform.root.GetComponent <Rigidbody>().angularVelocity = AngularVelocity;
                }
                Dropped = false;
            }
        }

        Velocity         = (transform.position - PreviousPosition) * (1f / Time.deltaTime);
        AngularVelocity  = ((transform.rotation * Vector3.forward) - PreviousRotation) * (1f / Time.deltaTime);
        PreviousPosition = transform.position;
        PreviousRotation = (transform.rotation * Vector3.forward);

        // cast ray to intersect objects
        RaycastHit hit;
        Vector3    dir      = transform.rotation * Vector3.forward;
        Ray        ClickRay = new Ray(transform.position, dir);

        if (Physics.Raycast(ClickRay, out hit))
        {
            //Debug.Log (hit.collider.name + " - " + hit.point);
            Vector3 targetDir = (hit.point - transform.position);
            //Debug.Log (targetDir.magnitude);
            Vector3 newScale = new Vector3(1, targetDir.magnitude, 1);
            LaserPointer.transform.localScale = newScale;
            LaserDot.SetActive(true);
            LaserDot.transform.localScale = newScale;

            // change size of the button
            if (hit.collider != PreviousCollider && PreviousCollider != null)
            {
                PreviousCollider.transform.localScale = Vector3.one;
                PreviousCollider = null;
            }

            if (hit.collider.tag == "UIButton")
            {
                //Debug.Log(hit.collider);
                if (PreviousCollider != hit.collider)
                {
                    Audio.PlayOneShot(SoundButtonHover);
                }
                hit.collider.transform.localScale = new Vector3(ButtonScaleAmount, ButtonScaleAmount, ButtonScaleAmount);
                PreviousCollider = hit.collider;
            }
        }
        else
        {
            LaserPointer.transform.localScale = new Vector3(1, 30, 1);
            LaserDot.SetActive(false);
        }
    }