// Update is called once per frame void Update() { Vector2 wid = new Vector2(Width / 2f, 0f);//This again calculates the width of the player Vector2 pos = gameObject.transform.position; //This finds the position of the player pos.y = pos.y - (height / 2) - 0.05f; //This calcultes the y position of the player Debug.DrawLine(pos + wid, pos + wid + Vector2.down); float t = Time.time - StartTime; //This finds the total time taken for the level so that it can be displayed in the corner of the screen. string minutes = ((int)t / 60).ToString(); //This calculates the minutes of the timer string seconds = (t % 60).ToString(); //This calculates the seconds of the timer if ((t % 60) < 10) { seconds = "0" + seconds; //If the amount of time is less than 1 minute, then it is set as seconds } TimerText.text = minutes + ":" + seconds.Substring(0, 2); //This displays the time in the corner of thescreen Debug.Log(RaycastDown()); if (Input.GetKeyDown("w") && RaycastDown()) //This is the jumping function, it checks whether the 'W' has been pressed and the uses the result of Raycastdown { GetComponent <Rigidbody2D>().AddForce(new Vector2(0, horizontalMove), ForceMode2D.Impulse); //This makes the player jump Debug.Log("Jump"); } if (Input.GetKey("a") && !Input.GetKey("d")) //This checks whether the 'A' key and not the 'D' key has been pressed { controller.Move(-runSpeed, false, false); //This makes the player move left animator.SetFloat("Speed", runSpeed); //This starts the running animation } else if (!Input.GetKey("a") && !Input.GetKey("d")) { animator.SetFloat("Speed", 0); //This stops the player moving and stops the running animation } if (Input.GetKey("d") && !Input.GetKey("a")) //This checks whether the 'D' key and not the 'A' key has been pressed { controller.Move(runSpeed, false, false); //This makes the player move right animator.SetFloat("Speed", runSpeed); //This starts the running animation } else if (!Input.GetKey("a") && !Input.GetKey("d")) { animator.SetFloat("Speed", 0);//This stops the layer moving and stops the running animation } }
// Update is called once per frame void Update() { if (Input.GetKeyDown("w") && RaycastDown()) { GetComponent <Rigidbody2D>().AddForce(new Vector2(0, horizontalMove), ForceMode2D.Impulse); } if (Input.GetKey("a") && !Input.GetKey("d")) { controller.Move(-runSpeed, false, false); } if (Input.GetKey("d") && !Input.GetKey("a")) { controller.Move(runSpeed, false, false); } }