示例#1
0
    public static Ammunition Fire(Ammunition AmmoToLoad, Transform Muzzle, GameObject Target = null)
    {
        if (AmmoToLoad == null)
        {
            return(null);
        }


        AmmoToLoad.MuzzleBang(Muzzle);

        GameObject shotgo = Instantiate(AmmoToLoad.gameObject, Muzzle.position, Muzzle.rotation);
        Ammunition shot   = shotgo.GetComponent <Ammunition>();


        shot.setShooter(Muzzle.gameObject);

        shot.shotrb = shot.GetComponent <Rigidbody>();

        shot.status = bulletState.firing;

        shot.initPosition = Muzzle.position;

        shot.smartTarget = Target;

        //get source velocity;
        if (shot.shotrb)
        {
            Vector3 InitialVelocity = Vector3.zero;

            if (Muzzle.GetComponentInParent <Rigidbody>())
            {
                InitialVelocity = Muzzle.GetComponentInParent <Rigidbody>().velocity;
            }

            shot.shotrb.velocity  = Muzzle.forward * shot.velocity;
            shot.shotrb.velocity += InitialVelocity;
        }

        if (shot.shotrb)
        {
            shot.shotrb.AddRelativeForce(Vector3.forward * shot.smartForce);
        }


        return(shot);
    }