Beispiel #1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        PlasmaShotScript shotScript = collider.gameObject.GetComponent <PlasmaShotScript> ();

        if (shotScript != null)
        {
            if (canBeCoveredInPlasma)
            {
                MoveScriptPlasma moveScript = collider.gameObject.GetComponent <MoveScriptPlasma>();
                massNeededForTransfer -= shotScript.plasmaShotMass;

                /* BEFORE! Before we destroy the collider's game object,
                 * have it talk to collider's -> Parent -> WeaponScript to set canTransferToTrue
                 * To: Prevent further shots from being fired, and to allow transfer (swap positions) */

                GameObject         colliderParent     = moveScript.parentWhoShot;
                PlasmaWeaponScript parentWeaponScript = colliderParent.GetComponent <PlasmaWeaponScript>();

                Destroy(shotScript.gameObject);

                if (massNeededForTransfer <= 0)
                {
                    // Change color, stop movement, and allow transfer.
                    parentWeaponScript.canTransfer = true;

                    // Instead of ^boolean, just set objectToTransferWith, and in WeaponScript, check if that object is null
                    parentWeaponScript.objectToTransferWith = gameObject;

                    spriteRenderer.color = Color.green;
                }
            }
        }
    }
Beispiel #2
0
    // Now, we instantiate a new plasmaShotPrefab if possible
    public void Attack()
    {
        if (rangeIndicatorTransform != null)
        {
            Destroy(rangeIndicatorTransform.gameObject);
        }
        // First, we need to check if player can transfer, if so, they can't fire more plasma
        if (objectToTransferWith != null)
        {
            // Now for some Captain Ginyu shit:
            Vector3 playerPosition = transform.position;

            transform.position = objectToTransferWith.transform.position;
            objectToTransferWith.transform.position = playerPosition;

            objectToTransferWith.GetComponent <PlasmaInteractionScript>().ResetSettings();
            objectToTransferWith = null;
        }
        else if (CanAttack)
        {
            shootCooldown = shootingRate;

            /* Now we instantiate a new shot and position it according to the
             * PlasmaWeaponScript's current position */
            var plasmaShotTransform = Instantiate(plasmaShotPrefab) as Transform;

            plasmaShotTransform.position = transform.position;

            //Make weapon shoot in direction of mouse
            MoveScriptPlasma moveScript = plasmaShotTransform.gameObject.GetComponent <MoveScriptPlasma>();
            moveScript.parentWhoShot = transform.gameObject;

            if (moveScript != null)
            {
                /* Must use ScreenToWorldPoint, since Input.mousePosition gets the mouse's actual position on the
                 * computer screen, so if your game window is half the size, in the middle, you'll get all kinds of
                 * messed up values */
                Vector3 worldMousePosition = Camera.main.ScreenPointToRay(Input.mousePosition).direction;
                // Turns out .magnitude is always returning 1... So I'll have to compute myself
                float computedMagnitude = Mathf.Sqrt(
                    Mathf.Pow(worldMousePosition.x, 2.0f) + Mathf.Pow(worldMousePosition.y, 2.0f));

                Vector3 mouseDirectionUnit = worldMousePosition * (1.0f / computedMagnitude);

                moveScript.directionUnitVector = mouseDirectionUnit;
            }
        }
    }