27. March, 2018
Puzzle game update 3
Added some water and a lot of logic and controls. Now you can swipe the camera around the board using mouse/touch from the sides of the screen. It also support levels, now after picking up the “gold” bricks the level changes.
The colors are a bit hard and the light beams are to bright.
Here are the code for the swiping camera (i had a hard time getting this to work and i couldn’t find any tutorials on this so i wanted to share it):
using UnityEngine; public class SwipeCamera : MonoBehaviour { public GameObject lookAt; public float minimum = 10.0F; public float maximum = 20.0F; public float duration = .05F; private Vector3 dragOrigin; private float snapDegrees = 90f; private float startTime; private float deg = 0; private bool draging = false; private float rotateTo = 0; private bool isMoveing = false; void Update() { SwipeRotateCam(); } void SwipeRotateCam() { transform.LookAt(lookAt.transform); if (isMoveing) { RotateCam(); return; } if (Input.GetMouseButtonDown(0)) { dragOrigin = Camera.main.ScreenToViewportPoint(Input.mousePosition); if (dragOrigin.x > 0.8f || dragOrigin.x < 0.2f) { draging = true; } } if (!Input.GetMouseButton(0) && draging && !isMoveing) { rotateTo = Mathf.DeltaAngle(Mathf.Repeat(deg, snapDegrees), snapDegrees); if (Mathf.Repeat(deg, snapDegrees) < (snapDegrees / 2)) rotateTo = -Mathf.Repeat(deg, snapDegrees); isMoveing = true; startTime = Time.time; tempRotateTo = rotateTo; deg = 0; draging = false; return; } if (!Input.GetMouseButton(0) || !draging) return; Vector3 mousePosNow = Camera.main.ScreenToViewportPoint(Input.mousePosition); float degRotate = (mousePosNow.x - dragOrigin.x) * 200; deg += degRotate; transform.RotateAround(lookAt.transform.position, Vector3.up, degRotate); dragOrigin = Camera.main.ScreenToViewportPoint(Input.mousePosition); } private float prevLerp = 0; private float tempRotateTo = 0; void RotateCam() { isMoveing = true; /* MOVE */ tempRotateTo -= prevLerp; prevLerp = Mathf.Lerp(0, tempRotateTo, Time.deltaTime * 10); transform.RotateAround(lookAt.transform.position, Vector3.up, Mathf.Lerp(0, tempRotateTo, Time.deltaTime * 10)); if (Mathf.Abs(prevLerp) <= 0.1) { transform.RotateAround(lookAt.transform.position, Vector3.up, tempRotateTo); // rotate remaning isMoveing = false; prevLerp = 0; tempRotateTo = 0; } /* / */ } }
Add tis script to your camera, but remember to set your camera tag to MainCamera. Then create and object for the camera to look at and reference it to the "Look At" object in the script.