Esempio n. 1
0
    void Awake()
    {
        inimigoBase = GetComponent <InimigoBaseScript>();
        rigid       = GetComponent <Rigidbody2D>();
        anim        = GetComponent <Animator>();

        originalScale = transform.localScale;

        state = CachorroStates.WAITING;
        anim.Play("Idle");
        direction = -1;
    }
Esempio n. 2
0
    // void OnBecameInvisible()
    // {
    // Destroy(gameObject);
    // }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            TriggerCollider.enabled = false;
            state = CachorroStates.ATTACKING;
            anim.Play("Attack");
        }
        if (other.CompareTag("KillPlane"))
        {
            Destroy(gameObject);
        }
    }
Esempio n. 3
0
    void FixedUpdate()
    {
        transform.localScale = new Vector3(
            originalScale.x * -direction,
            originalScale.y,
            1f);

        if (state == CachorroStates.RUNNING)
        {
            rigid.velocity = new Vector2(inimigoBase.speed * direction, rigid.velocity.y);
        }
        else if (state == CachorroStates.ATTACKING)
        {
            TriggerCollider.enabled = false;
            var leapForce = LeapDirection.normalized * inimigoBase.speed * rigid.mass * 100f;
            leapForce.x *= direction;
            rigid.AddForce(leapForce);

            state = CachorroStates.WAITING;
            anim.Play("Idle");
            Invoke("LeapEnd", 1.2f);
        }
    }
Esempio n. 4
0
 void OnBecameVisible()
 {
     state = CachorroStates.RUNNING;
     anim.Play("Run");
 }
Esempio n. 5
0
 void LeapEnd()
 {
     state = CachorroStates.RUNNING;
     anim.Play("Run");
     TriggerCollider.enabled = true;
 }