/*
     * void Fire(Vector2 Direction, GameObject fireObj)
     * {
     * if (((Mathf.Abs(Direction.x) > sensitivity && reloaded) || (Mathf.Abs(Direction.y) > sensitivity && reloaded)
     || Input.GetKeyDown(KeyCode.P)))
     ||{
     || if (Input.GetKeyDown(KeyCode.P))
     ||     Direction = new Vector2(1, 1);
     ||
     ||
     ||
     || AnimationAttacking(Direction);
     ||             if (clone != null)
     ||             {
     ||                     Destroy (clone);
     ||             }
     || clone = Instantiate(fireObj, transform.position, Quaternion.identity);
     || clone.GetComponent<Rigidbody2D>().AddForce(Direction.normalized * speed);
     || clone.GetComponent<Rigidbody2D>().gravityScale = flipValue;
     || reloaded = false;
     || setCooldown = cooldown;
     || direction = Vector2.zero;
     ||}
     ||
     ||Reload();
     ||}
     */

    void AnimationAttacking(Vector2 dir)
    {
        float dirXToOne   = dir.x > 0 ? 1 : -1;
        float LookAtToOne = lookingAt.x < 0 ? 1 : -1;

        // In short, we make sure the arm always throw "forward" from a sprite sense, and then when we want to cast forward, we just flip it aswell.
        // It gets the most natrual look.

        // Depending on which direction we're looking, we decide which direction is "forward".
        if (lookingAt.x > 0)
        {
            dir = new Vector2(Mathf.Abs(dir.x) * -1, (dir.y));
        }
        else
        {
            dir = new Vector2(Mathf.Abs(dir.x), dir.y);
        }

        throwArmSprite.enabled = true;
        armSprite.enabled      = false;

        Quaternion rot = Quaternion.LookRotation(dir);

        throwArm.transform.rotation = new Quaternion(0, 0, rot.z, rot.w);

        // Animation for the arm.
        throwArmAnim.Attack();

        if (dirXToOne != LookAtToOne && !isFlipped)
        {
            playerAnim.Flip();
            isFlipped = true;
        }
        animationPlaying = true;
    }
Ejemplo n.º 2
0
 void Kill(GameObject obj)
 {
     // If collide with player, kill the player
     if (obj.transform.tag == "Player")
     {
         obj.transform.GetComponent <Reviving>().Die();
         // obj.transform.GetComponent<Reviving>().die
         bAnim.Attack();
         attacking = true;
         Debug.Log("KILL PLAYER");
         AImove.Freeze(false, 0);
         GetComponent <Rigidbody2D>().velocity = Vector2.zero;
     }
 }
Ejemplo n.º 3
0
    // A sequence of events that composes the attacking
    private IEnumerator AttackInterval(float time)
    {
        bodyAnim.Attack();                                                                                             // Start the attacking animation

        attacking = true;                                                                                              // Prevent the movement code from running, and another attack from triggering
        rb.AddForce(new Vector2(0f, -speed * 24f), ForceMode2D.Impulse);                                               // Move upwards to show the imminent attack
        rb.velocity = Vector2.ClampMagnitude(rb.velocity, 2f);                                                         // Clamp the speed
        Vector2 targetingPos = playerTarget.position;                                                                  // Target where the player currently is, but only once

        sr.flipX = rb.velocity.x < 0f ? true : false;                                                                  // Flip the sprite in the direction of travel

        yield return(new WaitForSeconds(time));                                                                        // Wait

        Vector2 attackDir = new Vector2(targetingPos.x - transform.position.x, targetingPos.y - transform.position.y); // Get the direction towards where the player was

        rb.AddForce(attackDir.normalized * attackSpeed, ForceMode2D.Impulse);                                          // Fly quickly towards where the player used to be
        sr.flipX = attackDir.x < 0f ? true : false;                                                                    // Flip the sprite in the direction of attack
        FMODUnity.RuntimeManager.PlayOneShotAttached(attackEvent, gameObject);

        yield return(new WaitForSeconds(time)); // Wait

        attacking = false;                      // Stop attackin, re-enabling the movement code
    }