Simple gameplay loop in place

This commit is contained in:
2018-04-10 17:02:42 +10:00
parent 46836ca069
commit efe1cd63f5
25 changed files with 747 additions and 112 deletions
+42
View File
@@ -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
);
}
}