Init
This commit is contained in:
32
Assets/Scripts/CameraFollower.cs
Normal file
32
Assets/Scripts/CameraFollower.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollower : MonoBehaviour
|
||||
{
|
||||
public Vector3 smoothness = Vector3.one;
|
||||
public Vector3 offset;
|
||||
public float lookAtAngle = 10;
|
||||
public float fovBoost = 10;
|
||||
public Transform target;
|
||||
float defFov;
|
||||
void Start(){
|
||||
if(target == null) {target= PlayerController.instance.transform;}
|
||||
offset = transform.position - target.position;
|
||||
defFov = Camera.main.fieldOfView;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
Follow();
|
||||
}
|
||||
|
||||
|
||||
void Follow(){
|
||||
// transform.position = Vector3.Lerp(transform.position, target.position + offset, smoothness);
|
||||
transform.position = new Vector3(Mathf.Lerp(transform.position.x, target.position.x + offset.x, smoothness.x), Mathf.Lerp(transform.position.y,target.position.y+ offset.y, smoothness.y), Mathf.Lerp(transform.position.z,target.position.z+ offset.z, smoothness.z));
|
||||
transform.localEulerAngles = new Vector3(0, (transform.position.x - target.position.x) * lookAtAngle ,0);
|
||||
|
||||
Camera.main.fieldOfView = defFov + (Mathf.Abs((transform.position.x - target.position.x)) * fovBoost);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraFollower.cs.meta
Normal file
11
Assets/Scripts/CameraFollower.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42e0e01735c041fd5bf861e64f5821d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/GroundFollow.cs
Normal file
19
Assets/Scripts/GroundFollow.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GroundFollow : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
Vector3 offset;
|
||||
void Start()
|
||||
{
|
||||
offset =transform.position - target.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.position = new Vector3(target.position.x, transform.position.y, target.position.z + offset.z);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GroundFollow.cs.meta
Normal file
11
Assets/Scripts/GroundFollow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b3715955e03a27378be6de34d3e2355
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
59
Assets/Scripts/LevelGenerator.cs
Normal file
59
Assets/Scripts/LevelGenerator.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelGenerator : MonoBehaviour
|
||||
{
|
||||
public GameObject cube;
|
||||
|
||||
[Header("Spawn")]
|
||||
|
||||
public int minBlocks=2;
|
||||
public int maxBlocks = 5;
|
||||
public Vector3 minScale = Vector3.one;
|
||||
public Vector3 maxScale = new Vector3(2,8,2);
|
||||
public float rotationRange = 15;
|
||||
|
||||
public float distanceBetweenBlocks = 10;
|
||||
public float rowSpacing = 20;
|
||||
|
||||
public int curBlock = 1;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
float t =0;
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(PlayerController.instance.transform.position.z > (curBlock-3) * distanceBetweenBlocks){
|
||||
GenerateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GenerateBlock(){
|
||||
int cubesCount = Random.Range(minBlocks, maxBlocks);
|
||||
float baseX = PlayerController.instance.transform.position.x -Random.Range(rowSpacing /2f, rowSpacing);
|
||||
for(int j =0; j < 5; j++){
|
||||
bool flip = false;
|
||||
|
||||
for(int i =0; i < cubesCount; i++){
|
||||
float z = distanceBetweenBlocks * curBlock;
|
||||
|
||||
Vector3 size = new Vector3(Random.Range(minScale.x,maxScale.x),Random.Range(minScale.y,maxScale.y),Random.Range(minScale.z,maxScale.z));
|
||||
float x = baseX + (i * size.x * (flip ? -1 : 1));
|
||||
|
||||
GameObject newCube = Instantiate(cube, new Vector3(x,size.y * 0.4f,z), Quaternion.identity);
|
||||
newCube.transform.localScale = size;
|
||||
newCube.transform.Rotate(new Vector3(0,0, rotationRange * ((float)i / (float)cubesCount) * (flip ? 1 : -1)));
|
||||
flip = !flip;
|
||||
}
|
||||
|
||||
baseX += Random.Range(rowSpacing / 2f, rowSpacing);
|
||||
}
|
||||
|
||||
curBlock++;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LevelGenerator.cs.meta
Normal file
11
Assets/Scripts/LevelGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e5a98c9725be47c4b1fb585c6b1c9a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/Scripts/ObjectPool.cs
Normal file
44
Assets/Scripts/ObjectPool.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectPool : MonoBehaviour
|
||||
{
|
||||
public static ObjectPool instance;
|
||||
public static Dictionary<GameObject, List<Transform>> pool;
|
||||
void Awake(){
|
||||
instance= this;
|
||||
}
|
||||
|
||||
public static GameObject Spawn(GameObject obj, Vector3 position){
|
||||
if(pool.ContainsKey(obj)){
|
||||
//use from pool
|
||||
if(pool[obj].Count <=0){
|
||||
GameObject go = Instantiate(obj, position, Quaternion.identity);
|
||||
pool.Add(obj, new List<Transform>());
|
||||
pool[obj].Add(go.transform);
|
||||
return go;
|
||||
}else{
|
||||
GameObject chosen = pool[obj][0].gameObject;
|
||||
pool[obj].RemoveAt(0);
|
||||
return chosen;
|
||||
}
|
||||
}else{
|
||||
GameObject go = Instantiate(obj, position, Quaternion.identity);
|
||||
pool.Add(obj, new List<Transform>());
|
||||
pool[obj].Add(go.transform);
|
||||
return go;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void Despawn(GameObject obj){
|
||||
// if()
|
||||
}
|
||||
}
|
||||
|
||||
public class PoolItems{
|
||||
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/ObjectPool.cs.meta
Normal file
11
Assets/Scripts/ObjectPool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66366bcce2e1f46d98b67bbe5f158985
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Assets/Scripts/PlayerController.cs
Normal file
48
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public static PlayerController instance;
|
||||
public float movementSpeed = 10;
|
||||
public float turningSpeed = 1;
|
||||
public float turningSmoothness = 0.5f;
|
||||
public float turningRotation = 20;
|
||||
public float turningForce = 0;
|
||||
|
||||
void Awake(){
|
||||
instance =this;
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
// transform.Translate(Vector3.forward * movementSpeed);
|
||||
transform.position += new Vector3(0,0, movementSpeed);
|
||||
turningForce = Mathf.Lerp(turningForce, input*turningSpeed, turningSmoothness);
|
||||
// transform.Translate(Vector3.right * turningForce);
|
||||
transform.position += new Vector3(turningForce,0,0);
|
||||
|
||||
transform.localEulerAngles = new Vector3(0,0, turningForce * turningRotation);
|
||||
}
|
||||
|
||||
float input = 0;
|
||||
public void OnLeftPanel(){
|
||||
input = -1;
|
||||
}
|
||||
|
||||
public void OnRightPanel(){
|
||||
input = 1;
|
||||
}
|
||||
|
||||
public void OnPanelOff(){
|
||||
input =0;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerController.cs.meta
Normal file
11
Assets/Scripts/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99d4fc4c1723d2b0ba23ff2f889acd95
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user