Finished basic controls, worked on tile generation
This commit is contained in:
@@ -11,9 +11,11 @@ public class Controls : MonoBehaviour
|
||||
{
|
||||
public float MOVEMENTSPEED = 10f;
|
||||
public float SENSITIVITY = 10f;
|
||||
public Vector2 movement;
|
||||
public Vector2 rotation;
|
||||
public bool isAirborne;
|
||||
Vector2 movement;
|
||||
Vector2 rotation;
|
||||
bool isAirborne;
|
||||
bool isJumping;
|
||||
Vector3 lastDirection;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -21,6 +23,8 @@ public class Controls : MonoBehaviour
|
||||
movement = new Vector2();
|
||||
rotation = new Vector2();
|
||||
isAirborne = true;
|
||||
isJumping = false;
|
||||
lastDirection = new Vector3();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -37,6 +41,7 @@ public class Controls : MonoBehaviour
|
||||
else{
|
||||
GameObject.Find("Crosshair").transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void applyInput(){
|
||||
@@ -48,11 +53,14 @@ public class Controls : MonoBehaviour
|
||||
Vector3 lookDirection = new Vector3(0, rotation.x, 0) * Time.deltaTime * SENSITIVITY;
|
||||
gameObject.transform.Rotate(lookDirection);
|
||||
|
||||
if(isAirborne) return;
|
||||
|
||||
//Move Player object according to input and after rotation
|
||||
Vector3 direction = new Vector3(movement.x, 0, movement.y) * Time.deltaTime * MOVEMENTSPEED;
|
||||
gameObject.transform.Translate(direction);
|
||||
if(isAirborne){
|
||||
gameObject.transform.Translate(lastDirection);
|
||||
}
|
||||
else{
|
||||
Vector3 direction = new Vector3(movement.x, isJumping ? 0.5f : 0, movement.y) * Time.deltaTime * MOVEMENTSPEED;
|
||||
gameObject.transform.Translate(direction);
|
||||
lastDirection = direction;
|
||||
}
|
||||
}
|
||||
|
||||
void OnMove(InputValue direction){
|
||||
@@ -75,15 +83,21 @@ public class Controls : MonoBehaviour
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if(!isAirborne) return;
|
||||
if(col.gameObject.name.ToLower().Contains("plattform")){
|
||||
if(col.gameObject.name.ToLower().Contains("tile")){
|
||||
isAirborne = false;
|
||||
isJumping = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionExit(Collision col){
|
||||
if(isAirborne) return;
|
||||
if(col.gameObject.name.ToLower().Contains("plattform")){
|
||||
if(col.gameObject.name.ToLower().Contains("tile")){
|
||||
isAirborne = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnJump(){
|
||||
if(isAirborne) return;
|
||||
isJumping = true;
|
||||
}
|
||||
}
|
||||
|
||||
23
Assets/Scripts/Tile.cs
Normal file
23
Assets/Scripts/Tile.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Tile : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
|
||||
public float HIGHEST_POINT;
|
||||
public float LOWEST_POINT;
|
||||
public TileModifier MODIFIER;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.Find("Player");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Tile.cs.meta
Normal file
11
Assets/Scripts/Tile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4ad100ae18006c438490a7509944332
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/TileModifier.cs
Normal file
13
Assets/Scripts/TileModifier.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum TileModifier
|
||||
{
|
||||
FLAT,
|
||||
MOUNTAIN,
|
||||
LAKE,
|
||||
HILLS,
|
||||
RIVER,
|
||||
VALLEY
|
||||
}
|
||||
11
Assets/Scripts/TileModifier.cs.meta
Normal file
11
Assets/Scripts/TileModifier.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab6908fc67056662e8c1fba0a1b19320
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,13 +1,18 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WorldGenerator : MonoBehaviour
|
||||
{
|
||||
public List<GameObject> availableTiles;
|
||||
Dictionary<Vector3, GameObject> world;
|
||||
int SIZE = 10;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
world = new Dictionary<Vector3, GameObject>();
|
||||
generateWorld();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -15,4 +20,16 @@ public class WorldGenerator : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void generateWorld(){
|
||||
Vector3 position;
|
||||
GameObject tile;
|
||||
for(int i = 0; i < SIZE; i++){
|
||||
for(int j = 0; j < SIZE; j++){
|
||||
position = new Vector3(i, 0, j);
|
||||
tile = Instantiate(availableTiles[0], position * 100, Quaternion.identity);
|
||||
world.Add(position, tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user