Esempio n. 1
0
    //Create a projectile in the world
    void CreateProjectile()
    {
        //Temp offset variables
        float xOffset = projectileXOffset;
        float yOffset = projectileYOffset;

        //----------------------------------------------------
        //Create the projectile
        var projectileTransform = Instantiate(projectilePrefab)
                                  as Transform;

        //Create a pointer the the projectiles controller
        ProjectileController projectile = projectileTransform.
                                          gameObject.GetComponent <ProjectileController>();

        //Get the facing of the owner
        if (isPlayer)
        {
            facingRight = gameObject.GetComponent
                          <PlayerController>().facingRight;
        }
        else
        {
            facingRight = gameObject.GetComponent
                          <AIController>().facingRight;
        }
        //----------------------------------------------------

        //Make sure the projectile was created properly
        if (projectile != null)
        {
            //Check the owners facing
            if (!facingRight)
            {
                //Reverse the projectile art
                projectile.Flip();

                //Reverse the projectiles velocity
                xOffset *= -1;
            }
            //ADD Y FLIPPING AND VELOCITY CODE
        }

        //Move the projectile to the correct place
        projectileTransform.position = new Vector3
                                           (this.transform.position.x + xOffset,
                                           this.transform.position.y + yOffset,
                                           this.transform.position.z);
    }