Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C:\Users\Andrzej\Documents\Unity projekty\Space Shooter\Assets\Scripts\PlayerController.cs
- */
- using UnityEngine;
- using System.Collections;
- [System.Serializable]
- public class Boundary{
- public float xMin, xMax, zMin, zMax;
- }
- public class PlayerController : MonoBehaviour {
- public float speed;
- public Boundary boundary;
- public float tilt;
- public GameObject shot;
- public Transform shotSpawn;
- public float fireRate;
- private float nextFire;
- void Update(){
- if (Input.GetButton("Fire1") && Time.time > nextFire) {
- nextFire = Time.time + fireRate;
- Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
- audio.Play ();
- }
- }
- void FixedUpdate(){
- //na telefon ruch
- float moveHorizontal;// = Input.acceleration.x * 4f;
- float moveVertical; // = Input.acceleration.y * 4f;
- //na klawiature ruch
- //float moveHorizontal = Input.GetAxis("Horizontal");
- //float moveVertical = Input.GetAxis("Vertical");
- moveHorizontal = Input.GetAxis("Horizontal");
- moveVertical = Input.GetAxis("Vertical");
- //na telefon
- // moveHorizontal = Input.acceleration.x * 4f;
- // moveVertical = Input.acceleration.y * 4f;
- Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
- rigidbody.velocity = movement * speed;
- rigidbody.position = new Vector3
- (
- Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax),
- 0.0f,
- Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax)
- );
- rigidbody.rotation = Quaternion.Euler(0.0f,0.0f, rigidbody.velocity.x * -tilt);
- }
- }
- /*
- GameController.cs
- */
- using UnityEngine;
- using System.Collections;
- public class GameController : MonoBehaviour {
- public GameObject hazard;
- public Vector3 spawnValues;
- public int hazardCount;
- public float spawnWait;
- public float startWait;
- public float waveWait;
- public GUIText scoreText;
- public int score;
- public GUIText restartText;
- public GUIText gameOverText;
- private bool gameOver;
- private bool restart;
- void Start ()
- {
- gameOver = false;
- restart = false;
- restartText.text = "";
- gameOverText.text = "";
- score = 0;
- UpdateScore ();
- StartCoroutine (SpawnWaves ());
- }
- void Update ()
- {
- if (restart)
- {
- //nacisniecie klawisz R lub dotkniecie ekranu
- if (Input.GetKeyDown (KeyCode.R) || Input.touchCount > 0)
- {
- Application.LoadLevel (Application.loadedLevel);
- }
- if(Input.GetKeyDown (KeyCode.Q))
- Application.Quit();
- }
- }
- IEnumerator SpawnWaves ()
- {
- yield return new WaitForSeconds (startWait);
- while (true)
- {
- for (int i = 0; i < hazardCount; i++)
- {
- Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
- Quaternion spawnRotation = Quaternion.identity;
- Instantiate (hazard, spawnPosition, spawnRotation);
- yield return new WaitForSeconds (spawnWait);
- }
- yield return new WaitForSeconds (waveWait);
- if (gameOver)
- {
- // restartText.text = "Dotknij ekran aby zrestartować grę ";
- restartText.text = "Naciśnij 'R' aby zrestartować grę"; // + "\n" + "Q - wyjscie";
- //restartText.text = "'R' - restart" + "\n" + "Q - Quit";
- restart = true;
- break;
- }
- }
- }
- public void AddScore (int newScoreValue)
- {
- score += newScoreValue;
- UpdateScore ();
- }
- void UpdateScore ()
- {
- scoreText.text = "Wynik: " + score;
- //scoreText.text = "Your score: " + score;
- }
- public void GameOver ()
- {
- gameOverText.text = "Koniec gry!" + "\n" + "Autor: Andrzej Iwaniuk";
- //gameOverText.text = "Game over!" + "\n" + "Author: Andrzej Iwaniuk";
- gameOver = true;
- }
- }
- /*
- DestroyByBoundry.cs
- */
- using UnityEngine;
- using System.Collections;
- public class DestroyByBoundry : MonoBehaviour {
- void OnTriggerExit(Collider other) {
- // Destroy everything that leaves the trigger
- Destroy(other.gameObject);
- }
- }
- /*
- C:\Users\Andrzej\Documents\Unity projekty\Space Shooter\Assets\Scripts\GoogleMobileAdsDemoScript.cs
- */
- using System;
- using UnityEngine;
- using GoogleMobileAds;
- using GoogleMobileAds.Api;
- public class GoogleMobileAdsDemoHandler : IInAppPurchaseHandler
- {
- private readonly string[] validSkus = { "android.test.purchased" };
- //Will only be sent on a success.
- public void OnInAppPurchaseFinished(IInAppPurchaseResult result)
- {
- result.FinishPurchase();
- GoogleMobileAdsDemoScript.OutputMessage = "Purchase Succeeded! Credit user here.";
- }
- //Check SKU against valid SKUs.
- public bool IsValidPurchase(string sku)
- {
- foreach(string validSku in validSkus) {
- if (sku == validSku) {
- return true;
- }
- }
- return false;
- }
- //Return the app's public key.
- public string AndroidPublicKey
- {
- //In a real app, return public key instead of null.
- get { return null; }
- }
- }
- // Example script showing how to invoke the Google Mobile Ads Unity plugin.
- public class GoogleMobileAdsDemoScript : MonoBehaviour
- {
- private BannerView bannerView;
- private InterstitialAd interstitial;
- private static string outputMessage = "";
- public static string OutputMessage
- {
- set { outputMessage = value; }
- }
- //dodany kod przeze mnie
- void Start () {
- RequestBanner();
- bannerView.Show();
- }
- void OnDestroy() {
- bannerView.Destroy();
- }
- //dodany kod przeze mnie
- /*void OnGUI()
- {
- // Puts some basic buttons onto the screen.
- GUI.skin.button.fontSize = (int) (0.05f * Screen.height);
- GUI.skin.label.fontSize = (int) (0.025f * Screen.height);
- Rect requestBannerRect = new Rect(0.1f * Screen.width, 0.05f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(requestBannerRect, "Request Banner"))
- {
- RequestBanner();
- }
- Rect showBannerRect = new Rect(0.1f * Screen.width, 0.175f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(showBannerRect, "Show Banner"))
- {
- bannerView.Show();
- }
- Rect hideBannerRect = new Rect(0.1f * Screen.width, 0.3f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(hideBannerRect, "Hide Banner"))
- {
- bannerView.Hide();
- }
- Rect destroyBannerRect = new Rect(0.1f * Screen.width, 0.425f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(destroyBannerRect, "Destroy Banner"))
- {
- bannerView.Destroy();
- }
- Rect requestInterstitialRect = new Rect(0.1f * Screen.width, 0.55f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(requestInterstitialRect, "Request Interstitial"))
- {
- RequestInterstitial();
- }
- Rect showInterstitialRect = new Rect(0.1f * Screen.width, 0.675f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(showInterstitialRect, "Show Interstitial"))
- {
- ShowInterstitial();
- }
- Rect destroyInterstitialRect = new Rect(0.1f * Screen.width, 0.8f * Screen.height,
- 0.8f * Screen.width, 0.1f * Screen.height);
- if (GUI.Button(destroyInterstitialRect, "Destroy Interstitial"))
- {
- interstitial.Destroy();
- }
- Rect textOutputRect = new Rect(0.1f * Screen.width, 0.925f * Screen.height,
- 0.8f * Screen.width, 0.05f * Screen.height);
- GUI.Label(textOutputRect, outputMessage);
- }*/
- private void RequestBanner()
- {
- #if UNITY_EDITOR
- string adUnitId = "unused";
- #elif UNITY_ANDROID
- string adUnitId = "ca-app-pub-xxx"; //moj Google AdMob AdUnit
- #elif UNITY_IPHONE
- string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
- #else
- string adUnitId = "unexpected_platform";
- #endif
- // Create a 320x50 banner at the top of the screen.
- bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
- // Register for ad events.
- bannerView.AdLoaded += HandleAdLoaded;
- bannerView.AdFailedToLoad += HandleAdFailedToLoad;
- bannerView.AdOpened += HandleAdOpened;
- bannerView.AdClosing += HandleAdClosing;
- bannerView.AdClosed += HandleAdClosed;
- bannerView.AdLeftApplication += HandleAdLeftApplication;
- // Load a banner ad.
- bannerView.LoadAd(createAdRequest());
- }
- private void RequestInterstitial()
- {
- #if UNITY_EDITOR
- string adUnitId = "unused";
- #elif UNITY_ANDROID
- string adUnitId = "ca-app-pub-xxx"; //moj Google AdMob AdUnit
- #elif UNITY_IPHONE
- string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
- #else
- string adUnitId = "unexpected_platform";
- #endif
- // Create an interstitial.
- interstitial = new InterstitialAd(adUnitId);
- // Register for ad events.
- interstitial.AdLoaded += HandleInterstitialLoaded;
- interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad;
- interstitial.AdOpened += HandleInterstitialOpened;
- interstitial.AdClosing += HandleInterstitialClosing;
- interstitial.AdClosed += HandleInterstitialClosed;
- interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
- GoogleMobileAdsDemoHandler handler = new GoogleMobileAdsDemoHandler();
- interstitial.SetInAppPurchaseHandler(handler);
- // Load an interstitial ad.
- interstitial.LoadAd(createAdRequest());
- }
- // Returns an ad request with custom ad targeting.
- private AdRequest createAdRequest()
- {
- return new AdRequest.Builder()
- .AddTestDevice(AdRequest.TestDeviceSimulator)
- .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
- .AddKeyword("game")
- .SetGender(Gender.Male)
- .SetBirthday(new DateTime(1985, 1, 1))
- .TagForChildDirectedTreatment(false)
- .AddExtra("color_bg", "9B30FF")
- .Build();
- }
- private void ShowInterstitial()
- {
- if (interstitial.IsLoaded())
- {
- interstitial.Show();
- }
- else
- {
- print("Interstitial is not ready yet.");
- }
- }
- #region Banner callback handlers
- public void HandleAdLoaded(object sender, EventArgs args)
- {
- print("HandleAdLoaded event received.");
- }
- public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
- {
- print("HandleFailedToReceiveAd event received with message: " + args.Message);
- }
- public void HandleAdOpened(object sender, EventArgs args)
- {
- print("HandleAdOpened event received");
- }
- void HandleAdClosing(object sender, EventArgs args)
- {
- print("HandleAdClosing event received");
- }
- public void HandleAdClosed(object sender, EventArgs args)
- {
- print("HandleAdClosed event received");
- }
- public void HandleAdLeftApplication(object sender, EventArgs args)
- {
- print("HandleAdLeftApplication event received");
- }
- #endregion
- #region Interstitial callback handlers
- public void HandleInterstitialLoaded(object sender, EventArgs args)
- {
- print("HandleInterstitialLoaded event received.");
- }
- public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
- {
- print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
- }
- public void HandleInterstitialOpened(object sender, EventArgs args)
- {
- print("HandleInterstitialOpened event received");
- }
- void HandleInterstitialClosing(object sender, EventArgs args)
- {
- print("HandleInterstitialClosing event received");
- }
- public void HandleInterstitialClosed(object sender, EventArgs args)
- {
- print("HandleInterstitialClosed event received");
- }
- public void HandleInterstitialLeftApplication(object sender, EventArgs args)
- {
- print("HandleInterstitialLeftApplication event received");
- }
- #endregion
- }
- /*
- C:\Users\Andrzej\Documents\Unity projekty\Space Shooter\Assets\Scripts\RandomRotator.cs
- */
- using UnityEngine;
- using System.Collections;
- public class RandomRotator : MonoBehaviour {
- public float tumble;
- void Start ()
- {
- rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement