コード例 #1
0
    protected IEnumerator ShootPowered(Vector3 offset, bool shootLeft, int damageMultiplier, float speed, float charge)
    {
        // Prevents the player from moving
        // and puts them in a throwing animation.
        owner.canMove           = false;
        owner.body.gravityScale = 1.0f;
        owner.body.velocity     = Vector2.zero;
        owner.throwTime         = 0.1f;
        yield return(null);

        // Each shot is a simple big shot, with a small delay between shots.
        for (int i = 0; i < 3; i++)
        {
            // Sets the velocity, position and orientation of each shot.
            owner.body.velocity = -owner.right * 70.0f + owner.up * 100.0f;
            Pl_Shot newShot = Object.Instantiate(Resources.Load <Pl_Shot>("Prefabs/PlayerWeapons/PharaohShotPowered"));
            newShot.transform.position = owner.transform.position + offset;
            if (shootLeft)
            {
                newShot.transform.localScale = Vector3.Scale(newShot.transform.localScale, new Vector3(-1, 1, 1));
            }

            // Sets the damage of and starts the shot.
            newShot.damage *= damageMultiplier;
            newShot.Start();

            // Adds a small delay after every shot.
            yield return(new WaitForSecondsRealtime(0.1f));
        }

        // Lets the player move again.
        owner.canMove           = true;
        owner.body.gravityScale = 1.0f;
    }
コード例 #2
0
    protected void Shoot(Vector3 offset, bool shootLeft, int damageMultiplier, float speed, float charge)
    {
        // If there is no charge, creates a big shot,
        // and if there is enough charge, it selects the big
        // shot and tells it to no longer follow the player.
        // If there is some charge but not enough, or the big shot
        // has been destroyed, nothing happens.
        Pl_Shot newShot = null;

        if (charge == 0.0f)
        {
            newShot = Object.Instantiate(Resources.Load <Pl_Shot>("Prefabs/PlayerWeapons/PharaohShotsmall"));
        }
        else if (charge > 0.8f && shotBig)
        {
            newShot = shotBig;
            Object.Destroy(newShot.GetComponent <Misc_FollowTransform>());
            shotBig = null;
        }
        else
        {
            return;
        }


        // Both the big shot and small shot act the same,
        // so the newShot can be either.
        newShot.transform.position = owner.transform.position + offset;
        if (shootLeft)
        {
            newShot.transform.localScale = Vector3.Scale(newShot.transform.localScale, new Vector3(-1, 1, 1));
        }

        if ((Input.GetAxisRaw("Vertical") > 0.5f && !shootLeft) ||
            (Input.GetAxisRaw("Vertical") < -0.5f && shootLeft))
        {
            newShot.transform.eulerAngles += Vector3.forward * 45.0f;
        }
        if ((Input.GetAxisRaw("Vertical") < -0.5f && !shootLeft) ||
            (Input.GetAxisRaw("Vertical") > 0.5f && shootLeft))
        {
            newShot.transform.eulerAngles -= Vector3.forward * 45.0f;
        }

        // Sets the damage and speed, and starts the shot.
        newShot.damage *= damageMultiplier;
        newShot.speed   = speed;
        newShot.Start();
    }