示例#1
0
    //SoundPlayerScript SPS;
    //bool CanStepSound;
    //int StepCounter;

    // Use this for initialization
    void Start()
    {
        //CanStepSound = true;
        //StepCounter = 0;
        //SPS = GameObject.Find ("Main Camera").GetComponent<SoundPlayerScript> ();
        PauseScript = GameObject.Find("PauseMenuComponent").GetComponent <UIPauseMenuScript>();
        ES          = GameObject.Find("EternalHolder").GetComponent <EternalScript> ();
        RB          = GetComponent <Rigidbody2D> ();
        LR          = GetComponent <LineRenderer> ();
        RS          = GameObject.Find("RespawnObject").GetComponent <RespawnScript>();
        PauseScript.SetPlayer(PlayerNumber, this);
        AimingCursor.SetActive(false);
        ReticleRB = AimingCursor.GetComponent <Rigidbody2D> ();
        AimingCursor.GetComponent <SpriteRenderer> ().color = GetComponent <SpriteRenderer> ().color;
        Color C = ES.GetColor(PlayerNumber);

        C.r += .2f;
        C.g += .2f;
        C.b += .2f;
        Color C2 = C;

        C2.a = .2f;
        LR.SetColors(C, C2);
        currentRot = Quaternion.identity;
        if (BounceReticle)
        {
            LR.SetVertexCount(4);
        }
    }
    //SoundPlayerScript SPS;
    //bool CanStepSound;
    //int StepCounter;

    // Use this for initialization
    void Start()
    {
        //CanStepSound = true;
        //StepCounter = 0;
        //SPS = GameObject.Find ("Main Camera").GetComponent<SoundPlayerScript> ();
        PauseScript = GameObject.Find("PauseMenuComponent").GetComponent <UIPauseMenuScript>();
        RB          = GetComponent <Rigidbody2D> ();
        LR          = GetComponent <LineRenderer> ();
        RS          = GameObject.Find("RespawnObject").GetComponent <RespawnScript>();
        //PauseScript.SetPlayer (PlayerNumber, this);
        AimingCursor.SetActive(false);
        ReticleRB = AimingCursor.GetComponent <Rigidbody2D> ();
        AimingCursor.GetComponent <SpriteRenderer> ().color = GetComponent <SpriteRenderer> ().color;
    }
示例#3
0
    void AimButtonFunction()
    {
        // chekc if cursor is displayed
        if (AimingCursor.activeSelf == false)
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up);
            AimingCursor.transform.position = hit.point;
            AimingCursor.SetActive(true);
            IsAiming = true;
        }
        Vector3 tmp = Vector3.zero;

        if (Mathf.Abs(state.ThumbSticks.Right.X) > .25f)
        {
            tmp.x = state.ThumbSticks.Right.X * ReticleSpeed;
        }
        if (Mathf.Abs(state.ThumbSticks.Right.Y) > .25f)
        {
            tmp.y = state.ThumbSticks.Right.Y * ReticleSpeed;
        }
        ReticleRB.velocity = tmp;


        /*
         * if (Input.GetAxis (HoriztonalAxisS2) > .05) {
         *      ReticleRB.velocity = new Vector3 (ReticleSpeed * Input.GetAxis (HoriztonalAxisS2), ReticleRB.velocity.y, 0);
         * } else if (Input.GetAxis (HoriztonalAxisS2) < -.05) {
         *      ReticleRB.velocity = new Vector3 (ReticleSpeed* Input.GetAxis (HoriztonalAxisS2), ReticleRB.velocity.y, 0);
         * } else {
         *      ReticleRB.velocity = new Vector3 (0, ReticleRB.velocity.y, 0);
         * }
         *
         * // axis controls for vertical movement
         * if (Input.GetAxis (VerticalAxisS2) > .05) {
         *      ReticleRB.velocity = new Vector3 (ReticleRB.velocity.x, ReticleSpeed * Input.GetAxis (VerticalAxisS2), 0);
         * } else if (Input.GetAxis (VerticalAxisS2) < -.05) {
         *      ReticleRB.velocity = new Vector3 (ReticleRB.velocity.x, ReticleSpeed * Input.GetAxis (VerticalAxisS2), 0);
         * } else {
         *      ReticleRB.velocity = new Vector3 (ReticleRB.velocity.x, 0, 0);
         * }
         */
    }
    void AimButtonFunction()
    {
        // chekc if cursor is displayed
        if (AimingCursor.activeSelf == false)
        {
            RaycastHit2D hit = Physics2D.Raycast(GunPoint.position, transform.up);
            AimingCursor.transform.position = hit.point;
            AimingCursor.SetActive(true);
            IsAiming = true;
        }

        if (Input.GetAxis(HoriztonalAxisS2) > .05)
        {
            ReticleRB.velocity = new Vector3(ReticleSpeed * Input.GetAxis(HoriztonalAxisS2), ReticleRB.velocity.y, 0);
        }
        else if (Input.GetAxis(HoriztonalAxisS2) < -.05)
        {
            ReticleRB.velocity = new Vector3(ReticleSpeed * Input.GetAxis(HoriztonalAxisS2), ReticleRB.velocity.y, 0);
        }
        else
        {
            ReticleRB.velocity = new Vector3(0, ReticleRB.velocity.y, 0);
        }

        // axis controls for vertical movement
        if (Input.GetAxis(VerticalAxisS2) > .05)
        {
            ReticleRB.velocity = new Vector3(ReticleRB.velocity.x, ReticleSpeed * Input.GetAxis(VerticalAxisS2), 0);
        }
        else if (Input.GetAxis(VerticalAxisS2) < -.05)
        {
            ReticleRB.velocity = new Vector3(ReticleRB.velocity.x, ReticleSpeed * Input.GetAxis(VerticalAxisS2), 0);
        }
        else
        {
            ReticleRB.velocity = new Vector3(ReticleRB.velocity.x, 0, 0);
        }
    }
    // Update is called once per frame
    void Update()
    {
        // debug
        Debug.Log("Player numbner : " + PlayerNumber + "   " + Input.GetAxisRaw(FireButton));

        if (InputEnabled)
        {
            // axis crontrols for horizontal movement
            if (Input.GetAxis(HoriztonalAxis) > .05)
            {
                RB.velocity = new Vector3(5 * Input.GetAxis(HoriztonalAxis), RB.velocity.y, 0);
            }
            else if (Input.GetAxis(HoriztonalAxis) < -.05)
            {
                RB.velocity = new Vector3(5 * Input.GetAxis(HoriztonalAxis), RB.velocity.y, 0);
            }
            else
            {
                RB.velocity = new Vector3(0, RB.velocity.y, 0);
            }

            // axis controls for vertical movement
            if (Input.GetAxis(VerticalAxis) > .05)
            {
                RB.velocity = new Vector3(RB.velocity.x, 5 * Input.GetAxis(VerticalAxis), 0);
            }
            else if (Input.GetAxis(VerticalAxis) < -.05)
            {
                RB.velocity = new Vector3(RB.velocity.x, 5 * Input.GetAxis(VerticalAxis), 0);
            }
            else
            {
                RB.velocity = new Vector3(RB.velocity.x, 0, 0);
            }


            // aiming button controls
            if (Input.GetAxis(AimButton) > .5f && Controller)
            {
                AimButtonFunction();
            }
            else
            {
                if (AimingCursor.activeSelf == true)
                {
                    AimingCursor.SetActive(false);
                    IsAiming = false;
                }
            }
            transform.rotation = PointerRotation();
            LineControl();

            // input for shooting primary
            if (Input.GetAxis(FireButton) > .5f)
            {
                PrimaryWeapon(GunPoint.position, PointerRotation());
            }
            // input for shooting secondary
            if (Input.GetButton(FireSecondaryButton))
            {
                SecondaryWeapon(GunPoint.position, PointerRotation());
            }
            // menu control
            if (Input.GetButtonDown(MenuButton))
            {
                if (Time.timeScale == 1)
                {
                    InputEnabled = false;
                    PauseScript.PullUpMenu(PlayerNumber);
                }
            }
        }
    }
示例#6
0
    // Update is called once per frame
    void Update()
    {
        prevState = state;
        state     = GamePad.GetState(playerIndex, GamePadDeadZone.None);

        if (InputEnabled)
        {
            // axis crontrols for horizontal movement
            if (Mathf.Abs(state.ThumbSticks.Left.X) > deadSize)
            {
                xStick = state.ThumbSticks.Left.X;
            }
            else
            {
                xStick = 0;
            }
            if (Mathf.Abs(state.ThumbSticks.Left.Y) > deadSize)
            {
                yStick = state.ThumbSticks.Left.Y;
            }
            else
            {
                yStick = 0;
            }
            RB.velocity = new Vector3(xStick * 5, yStick * 5, 0);

            /*
             * if (Input.GetAxis (HoriztonalAxis) > .05) {
             *      RB.velocity = new Vector3 (5 * Input.GetAxis (HoriztonalAxis), RB.velocity.y, 0);
             * } else if (Input.GetAxis (HoriztonalAxis) < -.05) {
             *      RB.velocity = new Vector3 (5* Input.GetAxis (HoriztonalAxis), RB.velocity.y, 0);
             * } else {
             *      RB.velocity = new Vector3 (0, RB.velocity.y, 0);
             * }
             *
             * // axis controls for vertical movement
             * if (Input.GetAxis (VerticalAxis) > .05) {
             *      RB.velocity = new Vector3 (RB.velocity.x, 5 * Input.GetAxis (VerticalAxis), 0);
             * } else if (Input.GetAxis (VerticalAxis) < -.05) {
             *      RB.velocity = new Vector3 (RB.velocity.x, 5 * Input.GetAxis (VerticalAxis), 0);
             * } else {
             *      RB.velocity = new Vector3 (RB.velocity.x, 0, 0);
             * }
             */

            // aiming button controls
            if (state.Triggers.Left > .5f)                  //  && Controller){
            {
                AimButtonFunction();
            }
            else
            {
                if (AimingCursor.activeSelf == true)
                {
                    AimingCursor.SetActive(false);
                    IsAiming = false;
                }
            }
            transform.rotation = PointerRotation();
            distanceFar        = LineControl();

            // input for shooting primary
            if (state.Triggers.Right > .5f && canFirePrim && distanceFar)
            {
                PrimaryWeapon(GunPoint.position, PointerRotation());
                CanReleaseP = true;
            }
            // input for shooting primary release
            if (prevState.Triggers.Right > .5f && state.Triggers.Right <= .5f && CanReleaseP == true && PrimaryWeaponRelease != null)
            {
                PrimaryWeaponRelease(GunPoint.position, PointerRotation());
                CanReleaseP = false;
            }
            // inptut for secondary released
            if (state.Buttons.RightShoulder == ButtonState.Released && prevState.Buttons.RightShoulder == ButtonState.Pressed && CanReleaseS == true && SecondaryWeaponRelease != null)
            {
                SecondaryWeaponRelease(GunPoint.position, PointerRotation());
                CanReleaseS = false;
            }
            // input for shooting secondary
            if (state.Buttons.RightShoulder == ButtonState.Pressed && SecondaryWeapon != null)
            {
                SecondaryWeapon(GunPoint.position, PointerRotation());
                CanReleaseS = true;
            }
            // menu control
            if (state.Buttons.Start == ButtonState.Pressed && prevState.Buttons.Start == ButtonState.Released && Time.timeScale == 1)
            {
                InputEnabled = false;
                PauseScript.PullUpMenu(PlayerNumber);
            }
        }
        else
        {
            RB.velocity = Vector3.zero;
        }
    }