Player Controller and color changer
This commit is contained in:
19
Assets/Scripts/CameraController.cs
Normal file
19
Assets/Scripts/CameraController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
private Vector3 offset;
|
||||
|
||||
void Start()
|
||||
{
|
||||
offset = transform.position - player.transform.position;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
transform.position = player.transform.position + offset;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CameraController.cs.meta
Normal file
11
Assets/Scripts/CameraController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be9660cc0d9627849873ca175d296a63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/ColorManager.cs
Normal file
51
Assets/Scripts/ColorManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public enum Colors {
|
||||
None = -1,
|
||||
Grey,
|
||||
Red,
|
||||
Blue,
|
||||
Green,
|
||||
Yellow,
|
||||
Rainbow
|
||||
};
|
||||
|
||||
public class ColorManager : MonoBehaviour
|
||||
{
|
||||
public Material[] colorMaterials = new Material[Enum.GetNames(typeof(Colors)).Length];
|
||||
|
||||
public void WashColor(GameObject washed) {
|
||||
SetColor(Colors.Grey, washed);
|
||||
}
|
||||
|
||||
public void SetColor(Colors color, GameObject toPaint, Collision collision = null) {
|
||||
if(color == Colors.None) {
|
||||
if (collision.transform.CompareTag("ColorChanger")) {
|
||||
toPaint.GetComponent<Renderer>().material.color = collision.transform.GetComponent<Renderer>().material.color;
|
||||
}
|
||||
} else {
|
||||
toPaint.GetComponent<Renderer>().material.color = colorMaterials[(int)color].color;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void CheckGroundColor(GameObject collided) {
|
||||
if (transform.GetComponent<Renderer>().material.color != collided.transform.GetComponent<Renderer>().material.color) {
|
||||
Debug.Log("The colors are not the same! GroundColor: " + collided.transform.GetComponent<Renderer>().material.color + " PlayerColor: "
|
||||
+ transform.GetComponent<Renderer>().material.color);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision) {
|
||||
if (collision.collider.CompareTag("Water")) {
|
||||
WashColor(collision.gameObject);
|
||||
} else if (collision.collider.CompareTag("Ground")) {
|
||||
CheckGroundColor(collision.gameObject);
|
||||
} else if (collision.collider.CompareTag("ColorChanger")) {
|
||||
SetColor(Colors.None, transform.gameObject, collision);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ColorManager.cs.meta
Normal file
11
Assets/Scripts/ColorManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab4fe611c9713254e9fcc6e0de77f87f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Network.meta
Normal file
8
Assets/Scripts/Network.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09fd9c3cadd74f54c89d66ed044bff89
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Scripts/Network/DatabaseData.cs
Normal file
53
Assets/Scripts/Network/DatabaseData.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class DatabaseData : MonoBehaviour
|
||||
{
|
||||
public TMP_InputField input;
|
||||
|
||||
|
||||
public void GetData() => StartCoroutine(GetData_Coroutine());
|
||||
public void PostData() => StartCoroutine(PostData_Coroutine());
|
||||
|
||||
IEnumerator GetData_Coroutine() {
|
||||
input.text = "Loading...";
|
||||
|
||||
string uri = "http://localhost:3000/player";
|
||||
|
||||
using (UnityWebRequest request = UnityWebRequest.Get(uri)) {
|
||||
yield return request.SendWebRequest();
|
||||
|
||||
if(request.isNetworkError || request.isHttpError) { //lecserelni majd
|
||||
input.text = request.error;
|
||||
} else {
|
||||
input.text = request.downloadHandler.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator PostData_Coroutine() {
|
||||
input.text = "loading...";
|
||||
|
||||
string uri = "http://localhost:3000/newplayer";
|
||||
|
||||
/*List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
|
||||
formData.Add(new MultipartFormDataSection("field1=player_name"));
|
||||
formData.Add(new MultipartFormFileSection("bevitel1", "thewarrior1210"));*/
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("bevitel1","thewarrior1210");
|
||||
|
||||
using(UnityWebRequest request = UnityWebRequest.Post(uri, form)) {
|
||||
yield return request.SendWebRequest();
|
||||
|
||||
if (request.isNetworkError || request.isHttpError) { //lecserelni majd
|
||||
input.text = request.error;
|
||||
} else {
|
||||
input.text = request.downloadHandler.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Network/DatabaseData.cs.meta
Normal file
11
Assets/Scripts/Network/DatabaseData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e64f87fb66ea20a468ef1bdc205e7484
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Network/WriteFile.cs
Normal file
17
Assets/Scripts/Network/WriteFile.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
|
||||
public class WriteFile : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
public void writeUserName(string username) {
|
||||
StreamWriter writer = new StreamWriter(@"adat.txt", false);
|
||||
writer.Write(username);
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Network/WriteFile.cs.meta
Normal file
11
Assets/Scripts/Network/WriteFile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4102586368925fe449e8d028a1fee6c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Scripts/PlayerController.cs
Normal file
39
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public Rigidbody rb;
|
||||
public float moveSpeed = 5f;
|
||||
public float jumpforce = 5f;
|
||||
private Vector3 direction;
|
||||
private float horizontal, vertical, isJumping;
|
||||
private bool isOnGround;
|
||||
|
||||
private void Awake() {
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
horizontal = Input.GetAxis("Horizontal");
|
||||
vertical = Input.GetAxis("Vertical");
|
||||
isJumping = Input.GetAxis("Jump");
|
||||
|
||||
if (isJumping > 0 && isOnGround) {
|
||||
rb.AddForce(new Vector3(horizontal, jumpforce, vertical));
|
||||
isOnGround = false;
|
||||
}
|
||||
|
||||
direction = new Vector3(horizontal, 0,vertical);
|
||||
|
||||
rb.AddForce(direction * moveSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision) {
|
||||
if (collision.collider.CompareTag("Ground")) {
|
||||
isOnGround = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/PlayerController.cs.meta
Normal file
11
Assets/Scripts/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb738793c052dd54597cff2d5ea33de3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Scripts/SceneUIManager.cs
Normal file
33
Assets/Scripts/SceneUIManager.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SceneUIManager : MonoBehaviour
|
||||
{
|
||||
private int menuSceneIndex = 0, currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
|
||||
|
||||
public void LoadMenuScene() {
|
||||
SceneManager.LoadScene(menuSceneIndex);
|
||||
}
|
||||
|
||||
public void LoadPauseMenu() {
|
||||
//to be implemented when the ui is done
|
||||
}
|
||||
|
||||
public void LoadOptionsMenu() {
|
||||
//to be implemented when the ui is done
|
||||
}
|
||||
|
||||
public void LoadNextScene() {
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
||||
}
|
||||
|
||||
public void LoadScene(int sceneIndex) {
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
}
|
||||
|
||||
public void DisableUI(string UIName) {
|
||||
//to be implemented when some ui is done
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/SceneUIManager.cs.meta
Normal file
11
Assets/Scripts/SceneUIManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e14c8833040013f4f9c1d59cd1d9dd8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user