コード例 #1
0
    void OnTriggerEnter2D(Collider2D col)
    {
        IDamageable hitObj = col.GetComponent <IDamageable>();

        if (hitObj != null)
        {
            if ((damageableLayer.value >> col.gameObject.layer) == 1)
            {
                ApplyDamage(hitObj);
                OnHideObject?.Invoke(this);
            }
        }
        else if ((arrowLayer.value >> col.gameObject.layer) != 1)
        {
            OnHideObject?.Invoke(this);
        }
    }
コード例 #2
0
    protected void OnCollideWithEnemy()
    {
        PoolManager.Instance.UseObject(hitEffect, transform.position, Quaternion.identity);
            IDamageable hitObj = hit.collider.GetComponent<IDamageable>();
        if (hitObj != null)
        {
            ApplyDamage(hitObj, damage.RandomValue());
            //Debug.Log("Headshot attı!");
        }

            IPushAble pushable = hit.collider.GetComponent<IPushAble>();
            if (pushable != null && applyPushForce)
            {
                Vector3 direction = (hit.transform.position - transform.position).normalized;
                pushable.ApplyPushForce(direction * pushForce);
            }
        OnHideObject?.Invoke(this);
    }
コード例 #3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        IDamageable hitObj = col.GetComponentInParent <IDamageable>();

        if (hitObj != null)
        {
            if ((damageableLayer.value >> col.gameObject.layer) == 1)
            {
                ApplyDamage(hitObj);
                OnHideObject?.Invoke(this);
            }
        }
        else
        {
            OnHideObject?.Invoke(this);
        }

        //PoolManager.Instance.UsePoolObject(hitEffect, transform.position, Quaternion.identity);
    }
コード例 #4
0
    protected void FixedUpdate()
    {
        ray.origin = transform.position;
        ray.direction = transform.forward;

        //if (Physics.Raycast(ray, out hit, deltaSpeed, hitMask))
        if (Physics.SphereCast(ray, radius, out hit, deltaSpeed, hitMask))
        {
            transform.Translate(Vector3.forward * hit.distance);

            if ((damageMask.value >> hit.collider.gameObject.layer) == 1)
            {
                OnCollideWithEnemy();
            }
            else if (reflectOnCollision)
            {
                Vector3 reflectDir = Vector3.Reflect(ray.direction, hit.normal);
                transform.rotation = Quaternion.LookRotation(reflectDir, Vector3.up);
                
                if (maxReflect > 0)
                {
                    maxReflect--;
                }
                else
                {
                    OnHideObject?.Invoke(this);
                }
            }
            else
            {
                PoolManager.Instance.UseObject(hitEffect, transform.position, Quaternion.identity);
                OnHideObject?.Invoke(this);
            }
        }
        else
        {
            transform.Translate(Vector3.forward * deltaSpeed);
        }
    }
コード例 #5
0
 public void Die()
 {
     health = maxHealth;
     OnHideObject?.Invoke(this);
 }