Esempio n. 1
0
    IEnumerator FireAdditionArrows(GameObject AmmoProjectile)
    {
        int totalNumberOfArchers = 5;

        //GameObject LastArrowFired = AmmoProjectile;

        for (int i = 1; i < totalNumberOfArchers; i++)
        {
            int offsetX = Random.Range(-2, 4);
            int offsetZ = Random.Range(-2, 3);

            GameObject newArrow = Instantiate(Ammo, new Vector3(AmmoLoadPos.transform.position.x + offsetX, AmmoLoadPos.transform.position.y, AmmoLoadPos.transform.position.z + offsetZ), AmmoLoadPos.transform.rotation) as GameObject;



            newArrow.transform.rotation = AmmoLoadPos.transform.rotation;

            //rotate the arrow - remove it created in correct direction
            //newArrow.transform.Rotate(0, +90, 0);

            newArrow.GetComponent <Collider>().enabled = true;


            //initialise rigidbody's gravity
            newArrow.GetComponent <Rigidbody>().useGravity = true;

            newArrow.GetComponent <Rigidbody>().AddForce(newArrow.transform.forward * ProjectileForceApplied, ForceMode.Impulse);
            Arrow_Projectile arrow = newArrow.GetComponent <Arrow_Projectile>();
            arrow.InFlight();
            yield return(new WaitForSeconds(0.1f));
        }
    }
Esempio n. 2
0
    public override void FireProjectile()
    {
        //disconnect ammo from parent - however keep the object in memory to align the ball when  firing
        var parentObj = AmmoProjectile.transform.parent;
        //as we are going to rotate the parent obj - will need to rotate it back - thus get its default rotation for later
        var temp = AmmoProjectile.transform.parent.rotation;

        //disconnect from parent
        AmmoProjectile.transform.parent = null;

        //enable the collider on the ammo so it can connect with other objects
        AmmoProjectile.GetComponent <Collider>().enabled = true;


        //initialise rigidbody's gravity
        AmmoProjectile.GetComponent <Rigidbody>().useGravity = true;
        //Get angle, if not 45deg set to 45deg

        //rotate the parent object - as below - cant seem to rotate the projectile the same
        //parentObj.Rotate(-45, 90, 0);

        // AmmoProjectile.transform.Rotate (-45,90,0);


        //addforce (fire) using projectile's parent forward force parameter
        AmmoProjectile.GetComponent <Rigidbody>().AddForce(AmmoProjectile.transform.forward * ProjectileForceApplied, ForceMode.Impulse);



        //now rotate parent object back to as its default
        parentObj.rotation = temp;
        //Weapon shown as not loaded
        weaponLoaded = false;

        Arrow_Projectile arrow = AmmoProjectile.GetComponent <Arrow_Projectile>();

        arrow.InFlight();
        arrow.AssignMainArrow();


        //camera follow until object destroyed
        CameraFollowProjectile();

        //tell camera manager that Animation has now stopped - so that it can follow the projectile
        CameraManagerInformAnimationBeingPlayed(false);

        FireArrowsWithSleepCoroutine(AmmoProjectile);
    }