コード例 #1
0
 void Update()
 {
     if (Input.GetKey(KeyCode.A))
     {
         transform.Translate(-speed * Time.deltaTime, 0, 0);
     }
     if (Input.GetKey(KeyCode.D))
     {
         transform.Translate(+speed * Time.deltaTime, 0, 0);
     }
     if (Input.GetKeyDown(KeyCode.W) && isOnGround)
     {
         rb.AddForce(jumpForce * Vector2.up);
         isOnGround = false;
         anim.SetBool("jump", true);
     }
     if (Input.GetKey(KeyCode.S))
     {
         transform.Translate(0, -speed * Time.deltaTime, 0);
     }
     if (Input.GetKey(KeyCode.E))
     {
         wp.Attack();
     }
 }
コード例 #2
0
    void FixedUpdate()
    {
        //Apply  Movement
        float   x = Input.GetAxisRaw("Horizontal");
        Vector2 v = rigidbody.velocity;

        v.x = x * speed;
        Debug.Log(v.x);

        if (v.x > 0.1 && v.x < -0.1)
        {
            anim.SetBool("running", false);
        }
        else
        {
            anim.SetBool("running", true);
        }
        if (v.x > 0)
        {
            sr.flipX = false;
        }
        else if (v.x < 0)
        {
            sr.flipX = true;
        }
        if (Input.GetButtonDown("Jump") && (v.y == 0 || canFly))
        {
            v.y = jumpSpeed;
        }

        if (v.y != 0)
        {
            anim.SetBool("air", true);
        }
        else
        {
            anim.SetBool("air", false);
        }

        rigidbody.velocity = v;
        // Attack with that weapon if you have
        if (Input.GetButtonDown("Fire1") && currentWeapon != null)
        {
            currentWeapon.Attack();
        }
        if (Input.GetButtonDown("Fire2"))
        {
            int i = (weapons.IndexOf(currentWeapon) + 1) % weapons.Count;
            SetCurrentWeapon(weapons[i]);
        }
        //Check for out
        if (transform.position.y < deadZone)
        {
            Debug.Log("Current Position" + transform.position.y + "is lower than" + deadZone);
            GetOut();
        }
        //rigidbody.AddForce(new Vector2(x * speed, 0));
    }