Hi I am working on a 2D Sidescroller I got the Keyboard controls working however I wanted to test now how the game would be playable with mouse controls, but I can’t figure out how to get these working.
The idea behin it is that the player ship can only move in the current camera viewport. If i move my mouse to the left the ships flies to the left etc.
here is my script for keyboard controls
var playerSpeed : int; var xOff : float; var yOff : float; function Update () { // amount to move Player xOff += (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime; yOff += (playerSpeed * Input.GetAxis("Vertical")) * Time.deltaTime; // restrict player to camera position if (xOff > Camera.main.orthographicSize * Camera.main.aspect) { xOff = Camera.main.orthographicSize * Camera.main.aspect; } if (xOff < -Camera.main.orthographicSize * Camera.main.aspect) { xOff = -Camera.main.orthographicSize * Camera.main.aspect; } this.transform.position.x = Camera.main.transform.position.x + xOff; this.transform.position.y = Camera.main.transform.position.y + yOff; if (yOff > Camera.main.orthographicSize) { yOff = Camera.main.orthographicSize; } if (yOff < -Camera.main.orthographicSize) { yOff = -Camera.main.orthographicSize; } } function OnTriggerEnter (collisionInfo : Collider) { if (collisionInfo.gameObject.tag == "Enviroment"){ Destroy(gameObject); } }
is there any simple solution to just change the keyboard input to mouse input ?