consolidate all repos to one for archive
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public class myScript : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI mssg1;
|
||||
|
||||
public TextMeshProUGUI mssg2;
|
||||
|
||||
public Camera mainCamera;
|
||||
|
||||
public List<GameObject> objects;
|
||||
|
||||
readonly List<Vector3> positions = new();
|
||||
|
||||
readonly List<GameObject> spawned = new();
|
||||
|
||||
int count = 0;
|
||||
float timePlaying = 0;
|
||||
bool gameOn = true;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
foreach (GameObject obj in objects)
|
||||
{
|
||||
positions.Add(obj.transform.position);
|
||||
Vector2 pos = Random.insideUnitCircle;
|
||||
Vector3 newPos = new(pos.x, obj.transform.position.y, pos.y);
|
||||
spawned.Add(Instantiate(obj, newPos, obj.transform.rotation));
|
||||
}
|
||||
mssg2.text = "Find";
|
||||
mssg1.text = objects[0].tag;
|
||||
}
|
||||
|
||||
void reTrow()
|
||||
{
|
||||
foreach (GameObject obj in spawned)
|
||||
{
|
||||
Vector2 pos = Random.insideUnitCircle;
|
||||
Vector3 newPos = new(pos.x, obj.transform.position.y, pos.y);
|
||||
obj.transform.position = newPos;
|
||||
obj.GetComponent<BoxCollider>().enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
void Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (!gameOn) return;
|
||||
|
||||
timePlaying += Time.deltaTime;
|
||||
|
||||
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
|
||||
{
|
||||
Ray ray = mainCamera.ScreenPointToRay(Input.GetTouch(0).position);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit))
|
||||
{
|
||||
GameObject pressedObject = hit.collider.gameObject;
|
||||
|
||||
if (pressedObject.CompareTag(objects[count].tag))
|
||||
{
|
||||
pressedObject.GetComponent<BoxCollider>().enabled = false;
|
||||
pressedObject.transform.position = positions[count];
|
||||
count++;
|
||||
|
||||
if (count > objects.Count - 1)
|
||||
{
|
||||
mssg2.text = "You Win";
|
||||
int sec = (int)timePlaying % 60;
|
||||
int min = (int)(timePlaying / 60);
|
||||
mssg1.text = string.Format("{0:00}:{1:00}", min, sec);
|
||||
gameOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mssg1.text = objects[count].tag;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
mssg1.text = objects[0].tag;
|
||||
reTrow();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
mssg1.text = e.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user