_
This commit is contained in:
@@ -6,8 +6,6 @@ public class Chytac : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
|
||||
public Rigidbody hrac;
|
||||
|
||||
public Vector3 rozdiel;
|
||||
|
||||
public Pohybovac mover;
|
||||
@@ -17,12 +15,19 @@ public class Chytac : MonoBehaviour
|
||||
bool caught = false;
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
Rigidbody hrac;
|
||||
|
||||
void start(){
|
||||
hrac = gameObject.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(Input.GetButtonDown("Fire1")){
|
||||
//rozdiel = hrac.position -
|
||||
RaycastHit[] hits = Physics.RaycastAll(transform.position, new Vector3(mover.xrot, 0f, mover.zrot));
|
||||
float mindist = 15f;
|
||||
caught = false;
|
||||
RaycastHit[] hits = Physics.RaycastAll(transform.position, new Vector3(mover.xrot, 0f, mover.zrot), 100);
|
||||
float mindist = 30f;
|
||||
|
||||
foreach (RaycastHit hit in hits){
|
||||
if (hit.collider.gameObject.name != "Bean"){
|
||||
@@ -35,15 +40,20 @@ public class Chytac : MonoBehaviour
|
||||
else{
|
||||
chytene = hit.collider.gameObject.transform.root.gameObject;
|
||||
}
|
||||
rozdiel = hrac.position - chytene.GetComponent<Rigidbody>().position;
|
||||
caught = true;
|
||||
if (chytene.TryGetComponent<Rigidbody>(out Rigidbody rbx)){
|
||||
Debug.Log(hrac.position);
|
||||
Debug.Log(rbx.position);
|
||||
Debug.Log("Chytene");
|
||||
rozdiel = hrac.position - rbx.position;
|
||||
caught = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Input.GetButton("Fire1")){
|
||||
if(caught){
|
||||
chytene.GetComponent<Rigidbody>().position = new Vector3(hrac.position.x + rozdiel.x, hrac.position.y + 4, hrac.position.z + rozdiel.z);
|
||||
chytene.GetComponent<Rigidbody>().position = new Vector3(hrac.position.x + rozdiel.x, hrac.position.y + 4f, hrac.position.z + rozdiel.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user