Example #1
0
    IEnumerator Attack()
    {
        while (true)
        {
            /*test the minimum distance to attack */
            if (Vector3.Distance(Player.position, transform.position) < 1.5)
            {
                transform.LookAt(Player.position);
                /*start animation attack*/
                _animator.SetBool("close", true);
                /*start sound attack*/
                whoosh.Play();
                yield return(new WaitForSeconds(1f));

                /*wait 1 second and test if the distance is enough close for touch
                 * after 1 seconds the candy is in the middle of animation. */
                if (Vector3.Distance(Player.position, transform.position) < 1)
                {
                    Reactive_target_player RTP = Player.GetComponent <Reactive_target_player>();
                    RTP.ReactoHit();
                }

                yield return(new WaitForSeconds(1f));

                /*the animation attack is finished*/
                _animator.SetBool("close", false);
            }
            /*wait 0.5 second for the next attack*/
            yield return(new WaitForSeconds(0.5f));
        }
    }
Example #2
0
    private void OnTriggerEnter(Collider other)
    {
        Reactive_target_player player = other.GetComponent <Reactive_target_player>();

        if (player != null)
        {
            player.ReactoHit();
        }
        Destroy(this.gameObject);
    }