Esempio n. 1
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.collider.CompareTag("Player"))
     {
         player.Damage(1f);
     }
 }
Esempio n. 2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Player"))
     {
         player.Damage(1f);
     }
 }
Esempio n. 3
0
    IEnumerator Shoot()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.right);

        Audio.PlayOneShot(AttackClip, 0.5f);
        if (hitInfo)
        {
            Player1 player = hitInfo.transform.GetComponent <Player1>();
            Enemy   enemy  = hitInfo.transform.GetComponent <Enemy>();
            if (player != null)
            {
                player.Damage();
            }
            else if (enemy != null)
            {
                enemy.Damage();
            }
            //Random.Range(fireY - errorDistance, fireY + errorDistance)
            firePoint.position = new Vector3(firePoint.position.x, fireY, firePoint.position.z);
            lineRenderer.SetPosition(0, firePoint.position);
            lineRenderer.SetPosition(1, hitInfo.point);
        }

        else
        {
            lineRenderer.SetPosition(0, firePoint.position);
            lineRenderer.SetPosition(1, firePoint.position + firePoint.right * 100);
        }

        lineRenderer.enabled = true;
        yield return(new WaitForSeconds(0.02f));

        lineRenderer.enabled = false;
    }
Esempio n. 4
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         player.Damage(1.0f);
         gameObject.GetComponent <Collider2D>().enabled = false;
     }
 }
Esempio n. 5
0
 // Update is called once per frame
 void Update()
 {
     //when the player doesnt equal null
     if (player != null)
     {
         //perform damage function
         player.Damage(damage, knockbackDirection, knockBackForce);
     }
 }
Esempio n. 6
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //dont allow the trigger to collide with another trigger
        if (other.isTrigger || other.gameObject.layer == LayerMask.NameToLayer("invisibleGround"))
        {
            return;
        }
        var damagable = other.GetComponent <IDamagable>();

        if (damagable != null)
        {
            //damage enemies on collision
            damagable.TakeDamage(damage);
        }
        if (other.CompareTag("Player"))
        {
            player.Damage(damage);
        }

        //destroy the bullet on collision
        Destroy(gameObject);
    }