Exemplo n.º 1
0
    //--Shoot implementation
    private void performShootFromPoint(GameObject inShootingPoint)
    {
        Vector2 thePointWorld = new Vector2();
        float   theRotation   = 0.0f;

        XMath.getFromTransform(
            ref thePointWorld, ref theRotation, inShootingPoint
            );
        Vector2 theDiraction = XMath.getDiractionVectorForAngle(theRotation);

        float theShootingDistance = 10.0f;

        RaycastHit2D[] theHits = Physics2D.RaycastAll(
            thePointWorld, theDiraction, theShootingDistance
            );

        Vector2    theHitPoint       = new Vector2();
        Vector2    theHitNormal      = new Vector2();
        Collider2D theHittedCollider = null;

        foreach (RaycastHit2D theHit in theHits)
        {
            if (shouldIgnoreColliderOnHit(theHit.collider))
            {
                continue;
            }

            theHittedCollider = theHit.collider;
            theHitPoint       = theHit.point;
            theHitNormal      = theHit.normal;
            break;
        }

        notifyEffectsAboutShoot(thePointWorld, theDiraction, theShootingDistance,
                                theHitPoint, !!theHittedCollider
                                );

        if (!theHittedCollider)
        {
            return;
        }
        Rigidbody2D theShootedRigidBody = theHittedCollider.gameObject.GetComponent <Rigidbody2D>();

        if (!theShootedRigidBody)
        {
            return;
        }

        float theForce = 30.0f;

        theShootedRigidBody.AddForceAtPosition(theDiraction * theForce, theHitPoint);

        var theDurability = theShootedRigidBody.gameObject.GetComponent <DurabilityComponent>();

        if (theDurability)
        {
            theDurability.changeHitPoints(-5.0f);
        }
    }
Exemplo n.º 2
0
    //--Shoot implementation
    private void performShootFromPoint(GameObject inShootingPoint)
    {
        Vector2 theRocketPosition = new Vector2();
        float   theRocketRotation = 0.0f;

        XMath.getFromTransform(
            ref theRocketPosition, ref theRocketRotation, inShootingPoint
            );

        RocketProjectileObject theRocket =
            XUtils.createObject(_projectilePrefab);

        theRocket.init(XUtils.verify(_owner));

        theRocket.transform.position = theRocketPosition;
        Vector3 theRotation = theRocket.transform.rotation.eulerAngles;

        theRotation.z = theRocketRotation;
        theRocket.transform.eulerAngles = theRotation;
    }