Simple gameplay loop in place
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour {
|
||||
public GameObject background;
|
||||
float speed;
|
||||
|
||||
void Awake() {
|
||||
speed = 0.1f;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
ScrollSideways ();
|
||||
}
|
||||
|
||||
void ScrollSideways() {
|
||||
//get the x & y of the mouse as a ratio
|
||||
float mouseX = Input.mousePosition.x / Screen.width;
|
||||
float mouseY = Input.mousePosition.y / Screen.height;
|
||||
|
||||
//move the camera
|
||||
Vector3 cameraPos = transform.position;
|
||||
|
||||
if (mouseX < 0.20) {
|
||||
cameraPos.x -= speed;
|
||||
}
|
||||
if (mouseX > 0.80) {
|
||||
cameraPos.x += speed;
|
||||
}
|
||||
|
||||
//clamp
|
||||
float bgWidth = background.GetComponent<Renderer>().bounds.extents.x;
|
||||
float bgHeight = background.GetComponent<Renderer>().bounds.extents.y;
|
||||
|
||||
transform.position = new Vector3 (
|
||||
Mathf.Clamp (cameraPos.x, background.transform.position.x - bgWidth/2, background.transform.position.x + bgWidth/2),
|
||||
Mathf.Clamp (cameraPos.y, background.transform.position.y - bgHeight/2, background.transform.position.y + bgHeight/2),
|
||||
transform.position.z
|
||||
);
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcc11d7b3ddd16145b76361d71d5a250
|
||||
timeCreated: 1523337593
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameController : MonoBehaviour {
|
||||
void Update() {
|
||||
if (Input.GetButtonDown ("Quit")) {
|
||||
Application.Quit ();
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18951b66066a27e469e4ff1a02456942
|
||||
timeCreated: 1523340110
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Monster : MonoBehaviour {
|
||||
void OnMouseOver() {
|
||||
if (Input.GetMouseButtonDown(0)) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eac2f64158454a043b4b2ed57afad7de
|
||||
timeCreated: 1523340710
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MonsterSpawner : MonoBehaviour {
|
||||
public GameObject monsterPrefab;
|
||||
public Vector2 motion;
|
||||
public float delay;
|
||||
|
||||
void Awake() {
|
||||
StartCoroutine (SpawnMonster ());
|
||||
}
|
||||
|
||||
IEnumerator SpawnMonster() {
|
||||
while(true) {
|
||||
yield return new WaitForSeconds (delay);
|
||||
GameObject monster = Instantiate (monsterPrefab);
|
||||
monster.transform.position = transform.position;
|
||||
monster.GetComponent<Rigidbody2D> ().velocity = motion;
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4587b3641b0d264cadb164f227e7b9f
|
||||
timeCreated: 1523341235
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user