2021-08-15 09:33:25 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Chytac : MonoBehaviour
|
|
|
|
{
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
|
|
public Vector3 rozdiel;
|
|
|
|
|
|
|
|
public Pohybovac mover;
|
|
|
|
|
2021-08-18 11:41:12 +02:00
|
|
|
|
|
|
|
public float offsetx;
|
|
|
|
|
|
|
|
public float offsety;
|
2021-08-15 09:33:25 +02:00
|
|
|
public GameObject chytene;
|
|
|
|
|
|
|
|
bool caught = false;
|
|
|
|
|
|
|
|
// Update is called once per frame
|
2021-08-15 12:14:03 +02:00
|
|
|
|
|
|
|
|
2021-08-15 09:33:25 +02:00
|
|
|
void Update()
|
|
|
|
{
|
2021-08-18 11:41:12 +02:00
|
|
|
Debug.Log(new Vector3(mover.zrot, 10f, mover.xrot));
|
2021-08-15 09:33:25 +02:00
|
|
|
if(Input.GetButtonDown("Fire1")){
|
2021-08-15 12:14:03 +02:00
|
|
|
caught = false;
|
2021-09-03 17:47:38 +02:00
|
|
|
RaycastHit[] hits = Physics.SphereCastAll(transform.position, 30f, new Vector3(mover.xrot + offsetx, mover.zrot + offsety, 0f), 30f);
|
2021-08-15 12:14:03 +02:00
|
|
|
float mindist = 30f;
|
2021-08-15 09:33:25 +02:00
|
|
|
|
|
|
|
foreach (RaycastHit hit in hits){
|
|
|
|
if (hit.collider.gameObject.name != "Bean"){
|
|
|
|
Debug.Log(hit.distance);
|
|
|
|
if (hit.distance < mindist){
|
|
|
|
mindist = hit.distance;
|
|
|
|
if(hit.collider.gameObject.tag == "NotToRoot"){
|
|
|
|
chytene = hit.collider.gameObject;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
chytene = hit.collider.gameObject.transform.root.gameObject;
|
|
|
|
}
|
2021-08-15 12:14:03 +02:00
|
|
|
if (chytene.TryGetComponent<Rigidbody>(out Rigidbody rbx)){
|
2021-08-15 12:46:28 +02:00
|
|
|
Debug.Log(transform.position);
|
2021-08-15 12:14:03 +02:00
|
|
|
Debug.Log(rbx.position);
|
|
|
|
Debug.Log("Chytene");
|
2021-08-15 12:46:28 +02:00
|
|
|
rozdiel = transform.position - rbx.position;
|
2021-08-15 12:14:03 +02:00
|
|
|
caught = true;
|
|
|
|
}
|
2021-08-15 09:33:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Input.GetButton("Fire1")){
|
|
|
|
if(caught){
|
2021-08-15 12:46:28 +02:00
|
|
|
chytene.GetComponent<Rigidbody>().position = new Vector3(transform.position.x + rozdiel.x, transform.position.y + 4f, transform.position.z + rozdiel.z);
|
2021-08-15 09:33:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|