private void OnTriggerEnter2D(Collider2D other)
    {
        myTags tags = other.GetComponent <myTags>();

        if (tags != null)
        {
            if (tags.isWall)
            {
                Destroy(gameObject);
            }
            if (tags.team != team && tags.team != 0)
            {
                unitInterface otherInterface = other.GetComponent <unitInterface>();
                Vector2       hitDirection   = transform.position - otherInterface.transform.position;
                int           blocked        = otherInterface.applyHit(hitDirection);
                if (blocked == 1)
                {
                    otherInterface.resourceHandler.applyShieldDamage((int)(damage * blockFactor));
                }
                else if (blocked == 0)
                {
                    otherInterface.resourceHandler.applyShieldDamage(damage);
                }
                Instantiate(hitSprite, other.transform.position, other.transform.rotation);
                Destroy(gameObject);
            }
        }
    }
Exemple #2
0
    private void OnTriggerExit2D(Collider2D other)
    {
        myTags tag_object = other.gameObject.GetComponent <myTags>();

        if (tag_object != null)
        {
            if (tag_object.isGround)
            {
                onGround -= 1;
            }
            if (tag_object.isWall)
            {
                onWall -= 1;
            }
        }
    }
Exemple #3
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        myTags tag_object = other.gameObject.GetComponent <myTags>();

        if (tag_object != null)
        {
            if (tag_object.isGround)
            {
                onGround      += 1;
                groundCollider = other;
            }
            if (tag_object.isWall)
            {
                onWall      += 1;
                wallCollider = other;
            }
        }
    }
Exemple #4
0
    public Vector3 getGravity(Vector3 pos)
    {
        Vector3 grav = Vector3.zero;

        foreach (GameObject source in Resources.FindObjectsOfTypeAll(typeof(GameObject)))
        {
            myTags tag_object = source.GetComponent <myTags>();
            if (tag_object != null && tag_object.gravityStrength != 0)
            {
                Vector3 sVec        = source.transform.position - pos;
                float   sourceScale = GravityScale * tag_object.gravityStrength;
                sVec = sVec / Mathf.Pow(sVec.magnitude, 2f);
                sVec = sVec * sourceScale;
                grav = grav + sVec;
            }
        }
        grav = grav * rigidbodyCast.mass;
        return(grav);
    }