コード例 #1
0
ファイル: PlayerMouvement.cs プロジェクト: Smcmax/GameJam
    // Update is called once per frame
    void Update()
    {
        horizontalMove = (Input.GetAxisRaw("Horizontal") * runspeed);

        bool jumpReady = Time.time * 1000 > Controller.lastLanding + (Controller.jumpCooldown * 1000);


        animator.SetFloat("speed", Mathf.Abs(m_rigidbody2d.velocity.x));



        if (Input.GetButtonDown("Jump") && jumpReady)
        {
            Controller.jump = true;

            animator.SetBool("isjumping", true);
        }
        else if (Input.GetButtonUp("Jump") && (!Controller.jumprelease) && m_rigidbody2d.velocity.y > 0)
        {
            if (m_rigidbody2d.velocity.y > 0)
            {
                m_rigidbody2d.velocity = new Vector2(m_rigidbody2d.velocity.x, m_rigidbody2d.velocity.y / halfjump);

                Controller.jumprelease = true;
            }
        }

        if (Input.GetButton("Fire1") && m_damager)
        {
            if (m_damager.Damage())
            {
                animator.SetBool("isattacking", true);
            }
        }
        else if (Input.GetButtonUp("Fire1") && m_damager)
        {
            animator.SetBool("isattacking", false);
        }
    }
コード例 #2
0
ファイル: Shot.cs プロジェクト: hrederik/SpaceDefender
 private void OnTriggerEnter(Collider collider)
 {
     _damager.Damage(collider.gameObject, _damage);
 }
コード例 #3
0
 private void OnCollisionEnter(Collision collision)
 {
     _damager.Damage(collision.gameObject, _damage);
 }
コード例 #4
0
    protected override void ComputeVelocity()
    {
        Vector2 move = Vector2.zero;

        move.x = Input.GetAxisRaw("Horizontal");

        if (Input.GetButtonDown("Jump") && grounded)
        {
            velocity.y = jumpSpeed.Value;
        }
        else if (Input.GetButtonUp("Jump"))
        {
            if (velocity.y > 0)
            {
                velocity.y *= 0.5f;
            }
        }

        if (Mathf.Abs(m_knockback.x) + Mathf.Abs(m_knockback.y) >= 0.5f)
        {
            move        = m_knockback;
            m_knockback = new Vector2(m_knockback.x / 1.2f, m_knockback.y / 1.2f);
        }

        targetVelocity = move * maxSpeed.Value;

        // Hook with Animator

        Direction = Input.GetAxisRaw("Horizontal");

        if (Direction != 0)
        {
            if (Direction == -1)
            {
                spriterenderer.flipX = true;
            }
            if (Direction == 1)
            {
                spriterenderer.flipX = false;
            }
        }

        animator.SetFloat("speed", Mathf.Abs(move.x));

        if (grounded == false)
        {
            animator.SetBool("isjumping", true);
        }
        else
        {
            animator.SetBool("isjumping", false);
        }

        if (Input.GetButtonDown("Fire1") && m_damager)
        {
            if (m_damager.Damage())
            {
                animator.SetBool("isattacking", true);
            }
        }
        else if (Input.GetButtonUp("Fire1") && m_damager)
        {
            animator.SetBool("isattacking", false);
        }
    }