This commit is contained in:
2022-06-25 15:42:49 +02:00
commit 1080b53db3
235 changed files with 25161 additions and 0 deletions

View File

@@ -0,0 +1,155 @@
using UnityEngine;
using System.Collections;
//load textmeshpro
using TMPro;
// This script moves the character controller forward
// and sideways based on the arrow keys.
// It also jumps when pressing space.
// Make sure to attach a character controller to the same game object.
// It is recommended that you make only one call to Move or SimpleMove per frame.
public class Character_ctrl : MonoBehaviour
{
CharacterController characterController;
Camera camera_obj;
//win sound
public HuDcko hudcko;
public AudioClip win_sound;
public AudioClip die_sound;
public AudioClip walk_sound;
public AudioClip jump_sound;
public AudioClip teleport_sound;
public GameObject spawnpoint;
public float speed = 6.0f;
//textmeshpro
public TextMeshProUGUI textmeshpro;
public TextMeshProUGUI hudko;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public float turnSpeed = 1.0f;
private float timeks = 0;
private bool passed = false;
Vector2 camerarot = new Vector2(0, 0);
private Vector3 moveDirection = Vector3.zero;
private Vector3 moveKeyb = Vector3.zero;
private bool ontop = false;
void Start()
{
characterController = GetComponent<CharacterController>();
camera_obj = GetComponentInChildren<Camera>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
characterController.enabled = false;
transform.position = spawnpoint.transform.position;
transform.rotation = spawnpoint.transform.rotation;
characterController.enabled = true;
}
void FixedUpdate()
{
if(timeks >= 0.2f){
timeks = 0;
passed = true;
}
else{
timeks += Time.fixedDeltaTime;
passed = false;
}
// We are grounded, so recalculate
// move direction directly from axes
//add mouse x and y to camera rotation
camerarot.x += Input.GetAxis("Mouse X");
camerarot.y += -Input.GetAxis("Mouse Y");
//use turn speed to rotate camera
camerarot.x *= turnSpeed;
camerarot.y *= turnSpeed;
//then modulo with 360 to keep it in range
camerarot.x %= 360;
camerarot.y %= 360;
//then apply to camera
//clip camerarot y to -90 to 90
if (camerarot.y > 90)
{
camerarot.y = 90;
}
if (camerarot.y < -90)
{
camerarot.y = -90;
}
camera_obj.transform.localRotation = Quaternion.Euler(camerarot.y, 0, 0);
transform.localRotation = Quaternion.Euler(0, camerarot.x, 0);
//then apply to character controller
//moveDirection = camera.transform.TransformDirection(moveDirection);
moveKeyb = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
//if moving and walk sound is not playing, play it
//add movekeyb to moveDirection while accounting for rotation of camera
moveDirection = transform.TransformDirection(moveKeyb);
//multiply moveDirection by speed
moveDirection *= speed;
if (characterController.isGrounded)
{
if (moveKeyb != Vector3.zero && !GetComponent<AudioSource>().isPlaying)
{
GetComponent<AudioSource>().clip = walk_sound;
GetComponent<AudioSource>().volume = 0.1f;
GetComponent<AudioSource>().Play();
}
if (Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpSpeed;
//if enabled textmeshpro disable
if (textmeshpro.enabled)
{
textmeshpro.enabled = false;
hudko.enabled = true;
}
//set location of sound to be the same as the character and play sound
AudioSource.PlayClipAtPoint(jump_sound, transform.position);
}
}
if (Input.GetButton("Fire1"))
{
if(passed){
AudioSource.PlayClipAtPoint(teleport_sound, transform.position);
if(ontop){
Debug.Log("moved to lower floor");
characterController.enabled = false;
transform.position = new Vector3(transform.position.x, transform.position.y - 920, transform.position.z);
characterController.enabled = true;
ontop = false;
}
else{
characterController.enabled = false;
transform.position = new Vector3(transform.position.x, transform.position.y + 920, transform.position.z);
characterController.enabled = true;
ontop = true;
Debug.Log("moved to upper floor");
}
AudioSource.PlayClipAtPoint(teleport_sound, transform.position);
}
}
if(transform.position.y <= -500){
AudioSource.PlayClipAtPoint(die_sound, transform.position);
characterController.enabled = false;
transform.position = spawnpoint.transform.position;
transform.rotation = spawnpoint.transform.rotation;
characterController.enabled = true;
AudioSource.PlayClipAtPoint(die_sound, transform.position);
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
moveDirection.y -= gravity * Time.fixedDeltaTime;
// Move the controller
characterController.Move(moveDirection * Time.fixedDeltaTime);
hudcko.ontop = ontop;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e347063b256b699748119bf08f26bbac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

44
Assets/Scripts/HuDcko.cs Normal file
View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Text;
public class HuDcko : MonoBehaviour
{
public int collectedcubes = 0;
public int collectedcubes_max = 0;
public bool ontop = false;
public string text = "";
public bool won = false;
public TextMeshProUGUI textmeshpro;
// Start is called before the first frame update
void Start()
{
textmeshpro = GetComponent<TextMeshProUGUI>();
}
// Update is called once per frame
void Update()
{
//prepare stringbuilder for textmeshpro
StringBuilder sb = new StringBuilder();
sb.Append("Collected cubes: ");
sb.Append(collectedcubes);
sb.Append("/");
sb.Append(collectedcubes_max);
sb.Append("\n");
sb.Append("On top: ");
sb.Append(ontop);
sb.Append("\n");
string hax = sb.ToString();
if (won)
{
textmeshpro.text = "You won!";
}
else
{
textmeshpro.text = hax;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53c97e303fd00932abf1fdbe7db0a39d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class Pukvbrane : MonoBehaviour
{
AudioSource audioSource;
public HuDcko hudcko;
public GameObject puk;
public int maxcubes = 20;
public int collectedcubes = 0;
public void PlaceObj(){
int x = Random.Range(-821, 1000);
int z = Random.Range(-950, 950);
int y = -55;
//pick y from either -75 and 845
if (Random.Range(0, 2) == 0)
{
y = 880;
}
GameObject iks = Instantiate(puk.gameObject, new Vector3(x, y, z), Quaternion.identity);
iks.SetActive(true);
}
void Start()
{
audioSource = GetComponent<AudioSource>();
PlaceObj();
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "puk")
{
audioSource.Play();
//generate two random numbers between -50 and 50
Destroy(collision.gameObject);
if (collectedcubes < maxcubes)
{
collectedcubes++;
PlaceObj();
}
else{
hudcko.won = true;
}
}
hudcko.collectedcubes = collectedcubes;
hudcko.collectedcubes_max = maxcubes;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18e38293a9c8ac985a272f6263ea0f3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bombspawner : MonoBehaviour
{
public GameObject totok;
public int maxcubes = 100;
void PlaceObj(){
int x = Random.Range(-821, 1000);
int z = Random.Range(-950, 950);
int y = 800;
//pick y from either -75 and 845
if (Random.Range(0, 2) == 0)
{
y = 1600;
}
GameObject iks = Instantiate(totok.gameObject, new Vector3(x, y, z), Quaternion.identity);
iks.SetActive(true);
} // Start is called before the first frame update
void Start()
{
for (int i = 0; i < maxcubes; i++)
{
PlaceObj();
}
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4131aab71ffffd6088cba293cebec5e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

44
Assets/Scripts/yolo.cs Normal file
View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class yolo : MonoBehaviour
{
public Pukvbrane pukvbrane;
public GameObject totok;
void PlaceObj(){
int x = Random.Range(-821, 1000);
int z = Random.Range(-950, 950);
int y = 800;
//pick y from either -75 and 845
if (Random.Range(0, 2) == 0)
{
y = 1600;
}
GameObject iks = Instantiate(totok.gameObject, new Vector3(x, y, z), Quaternion.identity);
iks.SetActive(true);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter(Collision other) {
if(other.gameObject.tag == "Player"){
pukvbrane.collectedcubes = 0;
}
else if (other.gameObject.tag == "puk"){
Destroy(other.gameObject);
pukvbrane.PlaceObj();
}
PlaceObj();
Destroy(this.gameObject);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8cf7eb9351cc597d09f69c62637d019d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: