Beispiel #1
0
        private IEnumerator ShootRoutine(float vv)
        {
            Vector2 startPos = transform.position + new Vector3(vv, 0, 0) + (transform.up * 0.8f);

            // Fire a shell
            TankShell shell = TankShell.Shoot(bulletObject, startPos, transform.up);

            // Wait for the shell to be destroyed
            while (shell.Step() == false)
            {
                // Wait for next frame
                yield return(null);
            }

            // Destroy the shell
            shell.Destroy();
        }
        /// <summary>
        /// Create a tank shell using the specified values.
        /// </summary>
        /// <param name="prefab">The shell prefab to instantiate</param>
        /// <param name="startPosition">The start position of the shell</param>
        /// <param name="heading">The direction vector that the shell is heading in</param>
        /// <returns>An instance of <see cref="TankShell"/></returns>
        public static TankShell Shoot(GameObject prefab, Vector2 startPosition, Vector2 heading)
        {
            // Create a shell
            GameObject shell = Instantiate(prefab, startPosition, Quaternion.identity) as GameObject;

            // Get the script
            TankShell script = shell.GetComponent <TankShell>();

            // Check for error
            if (script == null)
            {
                Destroy(shell);
                return(null);
            }

            // Store the heading
            script.startPosition = startPosition;
            script.heading       = heading;

            return(script);
        }