// Update is called once per frame void Update() { if (controlMode) { gameUIText.text = "Control Mode: Mouse" + " Egg Count = " + eggCount + " Enemy Count = " + numberOfPlanes + " Planes Touched = " + planeTouches + " Planes Destroyed: " + destroyedCount; } else { gameUIText.text = "Control Mode: Mouse" + " Egg Count = " + eggCount + " Enemy Count = " + numberOfPlanes + " Planes Touched = " + planeTouches + " Planes Destroyed: " + destroyedCount; } if (Input.GetKey(KeyCode.Q)) { #if UNITY_EDITOR // Application.Quit() does not work in the editor so // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } if (numberOfPlanes < maxPlanes) { CameraSupport s = Camera.main.GetComponent <CameraSupport>(); GameObject e = Instantiate(Resources.Load("Prefabs/Enemy") as GameObject); // Prefab MUST BE locaed in Resources/Prefab folder! Vector3 pos; pos.x = (s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x) * 0.9f; pos.y = (s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y) * 0.9f; pos.z = 0; e.transform.localPosition = pos; ++numberOfPlanes; } }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Escape)) { #if UNITY_EDITOR // Application.Quit() does not work in the editor so // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } if (numberOfPlanes < maxPlanes) { CameraSupport s = Camera.main.GetComponent <CameraSupport>(); Assert.IsTrue(s != null); GameObject e = Instantiate(Resources.Load("Prefabs/Enemy") as GameObject); // Prefab MUST BE locaed in Resources/Prefab folder! Vector3 pos; pos.x = s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x; pos.y = s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y; pos.z = 0; e.transform.localPosition = pos; ++numberOfPlanes; } }
void Update() { if (Input.GetKey(KeyCode.Escape)) { #if UNITY_EDITOR // Application.Quit() does not work in the editor so // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } if (numberOfPlanes < maxPlanes && Time.frameCount % 1000 == 0) { CameraSupport s = Camera.main.GetComponent <CameraSupport>(); Assert.IsTrue(s != null); GameObject e = Instantiate(Resources.Load("Prefabs/Enemy") as GameObject); // Prefab MUST BE locaed in Resources/Prefab folder! Vector3 pos; pos.x = s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x; pos.y = s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y; pos.z = 0; e.transform.localPosition = pos; ++numberOfPlanes; } //var way = GameObject.FindGameObjectsWithTag("Waypoints"); //if (Input.GetKeyDown(KeyCode.M)) //{ // bool wayPointsOnOff = !wayPointsBool; // foreach (GameObject x in way) // { // x.GetComponent<SpriteRenderer>().enabled = wayPointsOnOff; // } //} }
// Update is called once per frame void Update() { Vector3 p = transform.localPosition; if (Input.GetKeyDown(KeyCode.Space)) { mFollowMousePosition = !mFollowMousePosition; } if (mFollowMousePosition) { p = Camera.main.ScreenToWorldPoint(Input.mousePosition); p.z = 0f; // <-- this is VERY IMPORTANT! // Debug.Log("Screen Point:" + Input.mousePosition + " World Point:" + p); } else { if (Input.GetKey(KeyCode.W)) { p += ((mHeroSpeed * Time.smoothDeltaTime) * transform.up); } if (Input.GetKey(KeyCode.S)) { p -= ((mHeroSpeed * Time.smoothDeltaTime) * transform.up); } if (Input.GetKey(KeyCode.A)) { transform.Rotate(transform.forward, mHeroRotateSpeed * Time.smoothDeltaTime); } if (Input.GetKey(KeyCode.D)) { transform.Rotate(transform.forward, -mHeroRotateSpeed * Time.smoothDeltaTime); } CameraSupport s = Camera.main.GetComponent <CameraSupport>(); // Try to access the CameraSupport component on the MainCamera if (s != null) // if main camera does not have the script, this will be null { Bounds myBound = GetComponent <Renderer>().bounds; // this is the bound of the collider defined on GreenUp CameraSupport.WorldBoundStatus status = s.CollideWorldBound(myBound); if (status != CameraSupport.WorldBoundStatus.Inside) { Debug.Log("Touching the world edge: " + status); // now let's re-spawn ourself somewhere in the world p.x = s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x; p.y = s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y; } } } transform.localPosition = p; }
public Bounds GetTargetBound() { Bounds targetB = mCameraSupport.GetWorldBound(); targetB.size = targetB.size * mTargetSize.value(); return(targetB); }
// Update is called once per frame void Update() { Vector3 p = transform.localPosition; if (Input.GetKey(KeyCode.W)) { p.y += kDelta; } if (Input.GetKey(KeyCode.S)) { p.y -= kDelta; } if (Input.GetKey(KeyCode.A)) { p.x -= kDelta; } if (Input.GetKey(KeyCode.D)) { p.x += kDelta; } // 1. Find the main camera and get the CameraSupport component CameraSupport s = Camera.main.GetComponent <CameraSupport>(); // Try to access the CameraSupport component on the MainCamera if (s != null) // if main camera does not have the script, this will be null { // intersect my bond with the bounds of the world Bounds myBound = GetComponent <Renderer>().bounds; // this is the bound on the SpriteRenderer CameraSupport.WorldBoundStatus status = s.CollideWorldBound(myBound); // If result is not "inside", then, move the hero to a random position if (status != CameraSupport.WorldBoundStatus.Inside) { Debug.Log("Touching the world edge: " + status); // now let's re-spawn ourself somewhere in the world p.x = s.GetWorldBound().min.x + Random.value * s.GetWorldBound().size.x; p.y = s.GetWorldBound().min.y + Random.value * s.GetWorldBound().size.y; } } transform.localPosition = p; }
// Use this for initialization void Start() { GameManager.sTheGlobalBehavior = this; // Singleton pattern // This must occur before EnemySystem's Start(); Debug.Assert(mWayPoints != null); Debug.Assert(mHero != null); mMainCamera = Camera.main.GetComponent <CameraSupport>(); Debug.Assert(mMainCamera != null); Bounds b = mMainCamera.GetWorldBound(); mEnemySystem = new EnemySpawnSystem(b.min, b.max); // Make sure all enemy sees the same EnemySystem and WayPointSystem EnemyBehavior.InitializeEnemySystem(mEnemySystem, mWayPoints); mEnemySystem.GenerateEnemy(); // Can only create enemies when WayPoint is initialized in EnemyBehavior }