コード例 #1
0
    private void Update()
    {
        //Moves the player if he is able to
        if (CanMove)
        {
            float horizontal = Input.GetAxisRaw("Horizontal");
            float vertical   = Input.GetAxisRaw("Vertical");
            Movement(horizontal, vertical);

            FireCenter.SetActive(vertical > 0.1f);
            FireLeft.SetActive(horizontal > 0.1f);
            FireRight.SetActive(horizontal < -0.1f);
        }

        //Shoots if the player presses the space bar it shoots
        if (Input.GetButton("Jump") && Time.time > Timer)
        {
            ShootShot();
            Timer = Time.time + FireRate;
        }
        //Check if left the screen
        Vector3 zeroPoint = GameManager.GM.camera.ScreenToWorldPoint(new Vector3(0, 0, 0));
        Vector3 edgePoint = GameManager.GM.camera.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));

        if (transform.position.x < zeroPoint.x - ScreenPadding || transform.position.x > edgePoint.x + ScreenPadding ||
            transform.position.y < zeroPoint.y - ScreenPadding || transform.position.y > edgePoint.y + ScreenPadding)
        {
            GameManager.GM.PlayerLosesLife();
        }
    }
コード例 #2
0
 private void Awake()
 {
     rb2d = GetComponent <Rigidbody2D>();
     FireRight.SetActive(false);
     FireLeft.SetActive(false);
     FireCenter.SetActive(false);
 }