Exemplo n.º 1
0
    private void Update()
    {
        transform.position += transform.up * speed * Time.deltaTime;
        if (Time.time > lifeTime)
        {
            Destroy(gameObject);
        }



        RaycastHit2D rayHit = Physics2D.Raycast(transform.position, transform.up);

        if (rayHit.collider == null)
        {
            return;
        }
        if ((rayHit.transform.position - transform.position).magnitude < 3f)
        {
            switch (rayHit.collider.tag)
            {
            case "Enemy":
                AIHealth aiHealth = rayHit.collider.GetComponent <AIHealth>();
                aiHealth.Damage(damage);
                Destroy(gameObject);
                break;

            case "Destructible":
                Destructible destructible = rayHit.collider.GetComponent <Destructible>();
                destructible.TakeDamage(damage);
                Destroy(gameObject);
                break;
            }
        }
    }
Exemplo n.º 2
0
    void Melee()
    {
        RaycastHit2D rayHit = Physics2D.Raycast(transform.position, rayDir * 2f);

        if (rayHit.collider == null)
        {
            return;
        }

        if (rayHit.collider.tag == "Enemy")
        {
            AIHealth aiHealth = rayHit.collider.GetComponent <AIHealth>();
            aiHealth.Damage(curWeaponData.damageAmount);
        }
    }