Esempio n. 1
0
        /// <summary>
        /// This is the weapon fire code created for this example. It instantiates a cosmetic (not network synced) projectile.
        /// For a real project you should considered using pooled objects for projectiles.
        /// </summary>
        private void FireBullet(Frame frame, PlayerFireCustomMsg msg)
        {
            Vector3    originPos;
            Quaternion originRot;

            originPos = originGO.transform.position;
            originRot = originGO.transform.rotation;

            GameObject projGO = (projPoolId > -1) ?
                                Pool.Spawn(projPoolId, originPos, originRot, 3).gameObject :
                                CreatePlaceholderProjectile(originPos, originRot, false);

            //Rigidbody rb = projGO.GetComponent<Rigidbody>() ?? projGO.AddComponent<Rigidbody>();
            Rigidbody      rb      = projGO.GetComponent <Rigidbody>();
            INstProjectile nstProj = projGO.GetComponent <INstProjectile>();

            if (nstProj != null)
            {
                nstProj.OwnerNst = nst;
            }

            // This needs the projectile to have a RB, so add one if it is missing
            if (rb == null)
            {
                rb            = projGO.AddComponent <Rigidbody>();
                rb.useGravity = false;
            }

            rb.velocity = projGO.transform.forward * projVelocity;

            // Changes color to color sent over the network as an example of how to use the Custom Message
            projGO.GetComponentInChildren <MeshRenderer>().material.color = msg.color;
        }
Esempio n. 2
0
        /// <summary>
        /// This is the weapon fire code created for this example. It instantiates a cosmetic (not network synced) projectile.
        /// For a real project you should considered using pooled objects for projectiles.
        /// </summary>
        private void FireBullet(Frame frame, PlayerFireCustomMsg msg)
        {
            Vector3    originPos;
            Quaternion originRot;

            originPos = originGO.transform.position;
            originRot = originGO.transform.rotation;

            Pool poolProj = Pool.Spawn(projPrefab, originPos, originRot, lifespanSecs);

            INstProjectile nstProj = poolProj.gameObject.GetComponent <INstProjectile>();

            if (nstProj != null)
            {
                nstProj.OwnerNst = nst;
            }

            poolProj.rb.velocity = poolProj.gameObject.transform.forward * projVelocity;

            // Changes color to color sent over the network as an example of how to use the Custom Message
            poolProj.GetComponentInChildren <MeshRenderer>().material.color = msg.color;
        }