Esempio n. 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;
                }
            }
        }
    }
Esempio n. 2
0
    // For now just look for firing input
    void Update()
    {
        /* Because we use GetButtonDown, to show the rangeIndicator, so you can aim, then fire as soon as you let go
         * But this also makes it easy to just click down->up in a short time so you can fire quicker. */
        bool shoot = Input.GetButtonUp("Fire1");
        bool aim   = Input.GetButtonDown("Fire1");

        PlasmaWeaponScript weaponScript = GetComponent <PlasmaWeaponScript>();

        if (aim)
        {
            if (weaponScript != null)
            {
                weaponScript.AimProjectile();
            }
        }
        if (shoot)
        {
            if (weaponScript != null)
            {
                weaponScript.Attack();
            }
        }
    }