void Start() { pause = gameManager.GetComponent <PauseMenu>(); checkControllers = gameManager.GetComponent <CheckControllers>(); //audioSource = GetComponent<AudioSource>(); p2Controller = checkControllers.GetControllerTwoState(); //Screen size CanvasScaler scaler = controllerCursor.GetComponentInParent <CanvasScaler>(); float expectedAspectRatio = scaler.referenceResolution.x / scaler.referenceResolution.y; float aspectRatio = (float)Screen.width / (float)Screen.height; screenWidth = (aspectRatio / expectedAspectRatio) * (scaler.referenceResolution.x / 2); screenHeight = scaler.referenceResolution.y / 2; }
void Update() { //Move ghost with cursor MoveGhost(); //Get controller select p2Controller = checkControllers.GetControllerTwoState(); if (p2Controller && !pause.GameIsPaused) { if (Input.GetButtonDown("Place_Joy_2") && placeEnabled) { MoveGhost(); SetTrap(); } } //Reset queue's when tower rotates if (Input.GetButtonDown("Submit_Joy_2") && resetEnabled && !pause.GameIsPaused && numTimesRotated < 4 * (tower.GetComponentInChildren <NumberOfFloors>().NumFloors - 1) - 1) { //if(cam.GetComponent<CameraTwoRotator>().GetFloor() == tower.GetComponent<NumberOfFloors>().NumFloors && cam.GetComponent<CameraTwoRotator>().GetState() == 4) //{ // lastFace = true; //} numTimesRotated++; resetEnabled = false; StartCoroutine(EnableInput()); DestroyGhost(); ClearTrapQueue(); CreateTrapQueue(); if (p2Controller) { eventSystem.SetSelectedGameObject(queue[0]); } cursorMove.MovingTraps = true; controllerCursor.transform.localPosition = new Vector3(0, 130); } }
void Start() { //Get references pause = gameManager.GetComponent <PauseMenu>(); cs = GetComponent <CastSpell>(); audioSource = GetComponent <AudioSource>(); //Queue Initialization queue = new List <GameObject>(); cursorMove = GetComponent <MoveControllerCursor>(); active = true; CreateTrapQueue(); trapQueue.transform.SetAsLastSibling(); //Handle cursor or set buttons if controller connected checkControllers = gameManager.GetComponent <CheckControllers>(); p2Controller = checkControllers.GetControllerTwoState(); placeEnabled = true; if (p2Controller) { eventSystem.SetSelectedGameObject(queue[0].gameObject); } }
//Move cursor with grid void Update() { p2Controller = checkControllers.GetControllerTwoState(); if (p2Controller && !pause.GameIsPaused && MovingTraps) { Vector3 cursorPos = controllerCursor.GetComponent <RectTransform>().localPosition; if (Input.GetAxisRaw("Horizontal_Joy_2") > stickSensitivity && cursorHorizontalMove && cursorPos.x < screenWidth) { controllerCursor.GetComponent <RectTransform>().localPosition += new Vector3(cursorGrid, 0, 0); cursorHorizontalMove = false; StartCoroutine(EnableHorizontalCursorMove()); //audioSource.PlayOneShot(spaceSelectionSFX); } else if (Input.GetAxisRaw("Horizontal_Joy_2") < -stickSensitivity && cursorHorizontalMove && cursorPos.x > -screenWidth) { controllerCursor.GetComponent <RectTransform>().localPosition -= new Vector3(cursorGrid, 0, 0); cursorHorizontalMove = false; StartCoroutine(EnableHorizontalCursorMove()); //audioSource.PlayOneShot(spaceSelectionSFX); } else if (Input.GetAxisRaw("Vertical_Joy_2") > stickSensitivity && cursorVerticalMove && cursorPos.y < screenHeight) { controllerCursor.GetComponent <RectTransform>().localPosition += new Vector3(0, cursorGrid, 0); cursorVerticalMove = false; StartCoroutine(EnableVerticalCursorMove()); // audioSource.PlayOneShot(spaceSelectionSFX); } else if (Input.GetAxisRaw("Vertical_Joy_2") < -stickSensitivity && cursorVerticalMove && cursorPos.y > 0) { controllerCursor.GetComponent <RectTransform>().localPosition -= new Vector3(0, cursorGrid, 0); cursorVerticalMove = false; StartCoroutine(EnableVerticalCursorMove()); //audioSource.PlayOneShot(spaceSelectionSFX); } } else if (p2Controller && !pause.GameIsPaused && !MovingTraps) { if (SpellCastDirection == SpellDirection.Instant) { Vector3 cursorPos = controllerCursor.GetComponent <RectTransform>().localPosition; if (Input.GetAxisRaw("Vertical_Joy_2") > stickSensitivity && cursorPos.y < -55) { Vector3 pos = controllerCursor.transform.localPosition; pos.z = 35; controllerCursor.transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical_Joy_2") * freeRoamSpellSpeed, 0f)); } if (Input.GetAxisRaw("Vertical_Joy_2") < -stickSensitivity && cursorPos.y > -screenHeight) { Vector3 pos = controllerCursor.transform.localPosition; pos.z = 35; controllerCursor.transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical_Joy_2") * freeRoamSpellSpeed, 0f)); } if (Input.GetAxisRaw("Horizontal_Joy_2") < -stickSensitivity) { Vector3 pos = controllerCursor.transform.localPosition; pos.z = 35; if (controllerCursor.transform.localPosition.x > -screenWidth) { controllerCursor.transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal_Joy_2") * freeRoamSpellSpeed, 0f, 0f)); } } if (Input.GetAxisRaw("Horizontal_Joy_2") > stickSensitivity) { Vector3 pos = controllerCursor.transform.localPosition; pos.z = 35; if (controllerCursor.transform.localPosition.x < screenWidth) { controllerCursor.transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal_Joy_2") * freeRoamSpellSpeed, 0f, 0f)); } } } else if (SpellCastDirection == SpellDirection.Right) { Vector3 cursorPos = controllerCursor.GetComponent <RectTransform>().localPosition; if (Input.GetAxisRaw("Vertical_Joy_2") > stickSensitivity && cursorVerticalMove && cursorPos.y < -55) { controllerCursor.GetComponent <RectTransform>().localPosition += new Vector3(0, cursorGrid * spellBarSpeedMultiplier, 0); } else if (Input.GetAxisRaw("Vertical_Joy_2") < -stickSensitivity && cursorVerticalMove && cursorPos.y > -screenHeight) { controllerCursor.GetComponent <RectTransform>().localPosition -= new Vector3(0, cursorGrid * spellBarSpeedMultiplier, 0); } } else if (SpellCastDirection == SpellDirection.Ceiling) { Vector3 cursorPos = controllerCursor.GetComponent <RectTransform>().localPosition; if (Input.GetAxisRaw("Horizontal_Joy_2") > stickSensitivity && cursorHorizontalMove && cursorPos.x < screenWidth) { controllerCursor.GetComponent <RectTransform>().localPosition += new Vector3(cursorGrid * spellBarSpeedMultiplier, 0, 0); } else if (Input.GetAxisRaw("Horizontal_Joy_2") < -stickSensitivity && cursorHorizontalMove && cursorPos.x > -screenWidth) { controllerCursor.GetComponent <RectTransform>().localPosition -= new Vector3(cursorGrid * spellBarSpeedMultiplier, 0, 0); } } } }