108 lines
4.0 KiB
C#
108 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using System;
|
|
using UnityEngine;
|
|
using Unity.XR.CoreUtils;
|
|
//using UnityEngine.UIElements;
|
|
|
|
public class GameLogicSk3 : MonoBehaviour
|
|
{
|
|
public GameObject[] spPoints;
|
|
public GameObject[] objInScene;
|
|
public string[] objOrder;
|
|
public Transform mizaPos;
|
|
public TextMeshProUGUI mssg;
|
|
List<int> usedIndices = new List<int>();
|
|
GameObject Base;
|
|
|
|
int searchForObjIdx;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
int index = UnityEngine.Random.Range(0, spPoints.Length); ;
|
|
|
|
for (int i = 0; i < objInScene.Length; i++)
|
|
{
|
|
|
|
|
|
while (usedIndices.Contains(index))
|
|
{
|
|
index = UnityEngine.Random.Range(0, spPoints.Length);
|
|
}
|
|
GameObject target = spPoints[index];
|
|
usedIndices.Add(index);
|
|
|
|
GameObject.Instantiate(objInScene[i], target.transform.position, target.transform.rotation);
|
|
}
|
|
searchForObjIdx = 0;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
mssg.text = "Išči objekt: " + objOrder[searchForObjIdx];
|
|
|
|
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
|
|
{
|
|
Ray raycast = Camera.current.ScreenPointToRay(Input.GetTouch(0).position);
|
|
RaycastHit raycastHit;
|
|
|
|
if (Physics.Raycast(raycast, out raycastHit))
|
|
{
|
|
if (raycastHit.collider.gameObject.tag == objOrder[searchForObjIdx])
|
|
{
|
|
if(raycastHit.collider.gameObject.tag == "Miza")
|
|
{
|
|
raycastHit.collider.gameObject.transform.position = mizaPos.transform.position;
|
|
raycastHit.collider.gameObject.transform.rotation = mizaPos.transform.rotation;
|
|
Vector3 TmvV = mizaPos.transform.position;
|
|
TmvV.y += (float)0.5;
|
|
mizaPos.transform.position = TmvV;
|
|
Base = raycastHit.collider.gameObject;
|
|
}
|
|
else
|
|
{
|
|
if (raycastHit.collider.gameObject.tag == "Stol")
|
|
{
|
|
Transform trns = Base.transform.GetChild(9).transform;
|
|
raycastHit.collider.gameObject.transform.position = trns.transform.position;
|
|
//raycastHit.collider.gameObject.transform.rotation = trns.transform.rotation;
|
|
raycastHit.collider.gameObject.transform.localRotation = Quaternion.identity;
|
|
}
|
|
else
|
|
{
|
|
if (raycastHit.collider.gameObject.tag == "Prenosnik")
|
|
{
|
|
Transform trns = Base.transform.GetChild(5).transform;
|
|
raycastHit.collider.gameObject.transform.position = trns.transform.position;
|
|
raycastHit.collider.gameObject.transform.rotation = trns.transform.rotation;
|
|
|
|
}
|
|
else
|
|
{
|
|
raycastHit.collider.gameObject.transform.position = mizaPos.transform.position;
|
|
raycastHit.collider.gameObject.transform.rotation = mizaPos.transform.rotation;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
searchForObjIdx++;
|
|
|
|
if (searchForObjIdx == objInScene.Length)
|
|
{
|
|
mssg.text = " ";
|
|
TimerSk3 tmr = GetComponent<TimerSk3>();
|
|
tmr.StopTimer();
|
|
}
|
|
}
|
|
else {
|
|
// Na novo razmeci objekte
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|