init
This commit is contained in:
commit
27755409e3
195 changed files with 146336 additions and 0 deletions
17
Assets/Scripts/ButtonController.cs
Normal file
17
Assets/Scripts/ButtonController.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ButtonController : MonoBehaviour{
|
||||
|
||||
[SerializeField] ParticleSystem winParticles;
|
||||
bool won;
|
||||
|
||||
void OnTriggerEnter(Collider other){
|
||||
if (other.CompareTag("Piece") && !won){
|
||||
winParticles.Play();
|
||||
won = true;
|
||||
GameManager.instance.ButtonPressed();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/ButtonController.cs.meta
Normal file
11
Assets/Scripts/ButtonController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 99a256c76130eed45b9aed93716d84a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/GameManager.cs
Normal file
39
Assets/Scripts/GameManager.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GameManager : MonoBehaviour{
|
||||
|
||||
[SerializeField, Range(1f, 6f)] int numberOfButtons = 1;
|
||||
int remainingButtons;
|
||||
[SerializeField] int nextScene;
|
||||
[SerializeField, Range(0f, 10f)] float transitionDelay = 2f;
|
||||
|
||||
[SerializeField] Animator transition;
|
||||
|
||||
public static GameManager instance;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
remainingButtons = numberOfButtons;
|
||||
}
|
||||
|
||||
public void ButtonPressed(){
|
||||
remainingButtons--;
|
||||
if(remainingButtons == 0){
|
||||
StartCoroutine(Transition());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Transition(){
|
||||
yield return new WaitForSeconds(transitionDelay);
|
||||
transition.SetTrigger("Transition");
|
||||
yield return new WaitForSeconds(.5f);
|
||||
SceneManager.LoadSceneAsync(nextScene);
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameManager.cs.meta
Normal file
11
Assets/Scripts/GameManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4c353d6bf6e81ea43987471696c9515e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
85
Assets/Scripts/ObjectPlacer.cs
Normal file
85
Assets/Scripts/ObjectPlacer.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ObjectPlacer : MonoBehaviour{
|
||||
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField] LayerMask obstacleMask;
|
||||
[SerializeField] LayerMask pieceMask;
|
||||
[SerializeField] Camera cam;
|
||||
|
||||
[SerializeField] GameObject cube;
|
||||
PlacerObject placerObject;
|
||||
[SerializeField, Range(0f, 10f)] float rotationMultiplier = 5f;
|
||||
[SerializeField, Range(0f, 2f)] float pieceHeight = 1.5f;
|
||||
float cubeRotation;
|
||||
|
||||
[SerializeField] GameObject piece;
|
||||
|
||||
bool isMouseOverButton;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Canvas canvas;
|
||||
[SerializeField] TMP_Text remainingText;
|
||||
[SerializeField, Range(0f, 20f)] int piecesAvaiable;
|
||||
int piecesRemaining;
|
||||
|
||||
public bool playing;
|
||||
public static bool canvasHidden;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
placerObject = cube.GetComponent<PlacerObject>();
|
||||
piecesRemaining = piecesAvaiable;
|
||||
if (canvasHidden)
|
||||
canvas.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
if(Physics.Raycast(ray, out RaycastHit hit, 100f, groundMask) && !Physics.Raycast(ray, 100f, obstacleMask) && !isMouseOverButton && !playing){
|
||||
cube.SetActive(true);
|
||||
cube.transform.position = hit.point + Vector3.up * pieceHeight / 2;
|
||||
}else{
|
||||
cube.SetActive(false);
|
||||
}
|
||||
|
||||
cubeRotation += Input.mouseScrollDelta.y * rotationMultiplier;
|
||||
cube.transform.rotation = Quaternion.Euler(0f, cubeRotation, 0f);
|
||||
|
||||
if(Input.GetMouseButtonDown(1) && Physics.Raycast(ray, out RaycastHit pieceHit, 100f, pieceMask) && !Physics.Raycast(ray, 100f, obstacleMask) && !isMouseOverButton && !playing){
|
||||
Destroy(pieceHit.transform.gameObject);
|
||||
piecesRemaining++;
|
||||
}
|
||||
if (Input.GetMouseButtonDown(0) && piecesRemaining > 0 && placerObject.CanPlace && cube.activeSelf && !isMouseOverButton && !playing){
|
||||
piecesRemaining--;
|
||||
Instantiate(piece, cube.transform.position, Quaternion.Euler(0f, cubeRotation, 0f));
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Escape)){
|
||||
canvasHidden = !canvasHidden;
|
||||
canvas.gameObject.SetActive(!canvas.gameObject.activeSelf);
|
||||
isMouseOverButton = false;
|
||||
}
|
||||
|
||||
remainingText.text = "LEFT " + piecesRemaining;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.R)){
|
||||
Restart();
|
||||
}
|
||||
}
|
||||
|
||||
public void Restart(){
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
|
||||
public void MouseOverUI(bool over){
|
||||
isMouseOverButton = over;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ObjectPlacer.cs.meta
Normal file
11
Assets/Scripts/ObjectPlacer.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 85d60c4c7f95220418738fb22e58c169
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
31
Assets/Scripts/PlacerObject.cs
Normal file
31
Assets/Scripts/PlacerObject.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlacerObject : MonoBehaviour{
|
||||
|
||||
bool canPlace = true;
|
||||
public bool CanPlace { get { return canPlace; } }
|
||||
|
||||
[SerializeField] Color canPlaceColor, cannotPlaceColor;
|
||||
|
||||
Material material;
|
||||
|
||||
void Start(){
|
||||
material = GetComponent<MeshRenderer>().material;
|
||||
}
|
||||
|
||||
void OnTriggerStay(Collider other){
|
||||
if (other.CompareTag("Piece") || other.CompareTag("Button") || other.CompareTag("Obstacle")){
|
||||
canPlace = false;
|
||||
material.color = cannotPlaceColor;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider other){
|
||||
if (other.CompareTag("Piece") || other.CompareTag("Button") || other.CompareTag("Obstacle")){
|
||||
canPlace = true;
|
||||
material.color = canPlaceColor;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlacerObject.cs.meta
Normal file
11
Assets/Scripts/PlacerObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dffa75d9095395548ada03ea754b37ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
28
Assets/Scripts/StartGame.cs
Normal file
28
Assets/Scripts/StartGame.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StartGame : MonoBehaviour{
|
||||
|
||||
[SerializeField] float force = 5f, forceOffset = .5f;
|
||||
Rigidbody rb;
|
||||
|
||||
bool started;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.P))
|
||||
Play();
|
||||
}
|
||||
|
||||
public void Play(){
|
||||
if (started) return;
|
||||
rb.AddForceAtPosition(transform.forward * force, transform.position + transform.up * forceOffset, ForceMode.Impulse);
|
||||
FindObjectOfType<ObjectPlacer>().playing = true;
|
||||
started = true;
|
||||
}
|
||||
}
|
11
Assets/Scripts/StartGame.cs.meta
Normal file
11
Assets/Scripts/StartGame.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 979eae842d41604449ea248efa0fc039
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue