コード例 #1
0
    public static bool isHitstop(GameObject go)
    {
        Hitstop hs = go.GetComponent <Hitstop> ();

        if (!hs)
        {
            Debug.Log("no hs comp in " + go);
        }
        if (hs && hs.isHitstop())
        {
            return(true);
        }
        return(false);
    }
コード例 #2
0
 // Update is called once per frame
 void Update()
 {
     if (Hitstop.isHitstop(gameObject))
     {
         return;
     }
     if (stun > 0)
     {
         stun -= Time.deltaTime;
         return;
     }
     Move();
     Jump();
     //Crouch();
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (Hitstop.isHitstop(gameObject))
        {
            return;
        }

        if (Input.GetAxis("Horizontal_id" + player_id) > 0)
        {
            isFacingRight = true;
        }
        else if (Input.GetAxis("Horizontal_id" + player_id) < 0)
        {
            isFacingRight = false;
        }
        GetComponentInChildren <SpriteRenderer>().flipX = !isFacingRight;
    }
コード例 #4
0
    void FixedUpdate()
    {
        if (Hitstop.isHitstop(gameObject))
        {
            if (oldSpeed == null)
            {
                oldSpeed = rb.velocity;
            }
            rb.velocity = (Vector2)Vector2.zero;

            if (oldPos == null)
            {
                oldPos = rb.position;
            }
            rb.position = (Vector2)oldPos;

            return;
        }
        else
        {
            if (oldSpeed != null)
            {
                rb.velocity = (Vector2)oldSpeed;
                oldSpeed    = null;
            }
            if (oldPos != null)
            {
                oldPos = null;
            }
        }

        if (player && !player.isGrounded)
        {
            Vector2 v = new Vector2(0, gravity * Time.deltaTime);
            rb.velocity -= v;
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        if (Hitstop.isHitstop(gameObject))
        {
            return;
        }

        if (isAttacking)
        {
            runningTimer -= Time.deltaTime;
        }

        if (runningTimer < 0)
        {
            isAttacking = false;
        }

        if ((Input.GetButtonDown("Fire1_id" + player_id) || Input.GetButtonDown("Fire2_id" + player_id)) && !isAttacking)
        {
            //float inputDirection = Input.GetAxis("Horizontal");
            Vector2    playerMidPoint = (Vector2)GetComponent <Transform>().position;// + GetComponent<BoxCollider2D>().size / 2;
            GameObject newHitbox      = Instantiate(attack);

            Vector2 offSet = new Vector2(0, 0);

            if (Input.GetButtonDown("Fire1_id" + player_id))   // Strike. Able to set custom timers this way
            {
                Destroy(newHitbox, attack1ActiveTimer);
                offSet = new Vector2(0.6f, 0);
                newHitbox.GetComponent <Hitbox>().type         = 1;
                newHitbox.GetComponent <Hitbox>().startupTimer = attack1StartupTimer;
                runningTimer = attack1CooldownTimer;
            }
            else     // Bunt
            {
                Destroy(newHitbox, attack2ActiveTimer);
                newHitbox.transform.Rotate(0, 0, 90);
                offSet = new Vector2(0.5f, 0);
                newHitbox.GetComponent <Hitbox>().type         = 2;
                newHitbox.GetComponent <Hitbox>().startupTimer = attack2StartupTimer;
                runningTimer = attack2CooldownTimer;
            }



            if (GetComponent <Facing>().isFacingRight)
            {
                newHitbox.transform.position = new Vector2(offSet.x + playerMidPoint.x, offSet.y + playerMidPoint.y);
            }
            else
            {
                newHitbox.transform.position = new Vector2(-offSet.x + playerMidPoint.x, offSet.y + playerMidPoint.y);
                if (Input.GetButtonDown("Fire1_id" + player_id))                 // Cosmetic for current sprites
                {
                    newHitbox.GetComponent <SpriteRenderer>().flipX = false;
                }
                else
                {
                    newHitbox.GetComponent <SpriteRenderer>().flipY = true;
                }
            }

            newHitbox.transform.SetParent(GetComponent <Transform>());
            isAttacking = true;
        }
    }