I didn’t find solution, i have object hold script when i left the object unity gives child out of bounds error how can i fix it ?
video link:getchild problem - YouTube
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class HoldAcid : MonoBehaviour
{
public Transform player;
public Transform Kamera;
public Transform Obje;
private Camera playerCam;
public float throwForce = 10;
public bool beingCarried = false;
public AudioClip[] soundToPlay;
public float mesafe;
private Ray playerAim;
public float smooth;
void Start()
{
}
void FixedUpdate()
{
playerCam = Camera.main;
Ray playerAim = playerCam.GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hit;
if (Physics.Raycast(playerAim, out hit, mesafe))
{
if (Input.GetMouseButtonDown(0) && hit.collider.gameObject.tag != "tasinamayan" && beingCarried == false) // TERRAİNİ TAŞIYON DÜZELT
{
GameObject tekdondur = hit.collider.gameObject; // OBJELERİ AYRI AYRI TUTMA KODU
tekdondur.GetComponent<Rigidbody>().isKinematic = true;
tekdondur.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
tekdondur.transform.parent = Kamera; //AYRI TUTMA KODUNA BUDA DAHİL
//tekdondur.transform.SetParent(Kamera);
beingCarried = true;
}
}
if (beingCarried)
{
GameObject tekdondur = Kamera.transform.GetChild(0).gameObject; //TEK DÖNDÜRMEYE KODU
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
tekdondur.transform.Rotate(Camera.main.transform.right, smooth * Time.deltaTime, Space.World);
}
if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
tekdondur.transform.Rotate(-Camera.main.transform.right, smooth * Time.deltaTime, Space.World);
//kameranın baktığı yönde döndürme tekdondur. olmadanki hali
}
//if (Input.GetMouseButtonDown(0))
//{
// GetComponent<Rigidbody>().isKinematic = false;
//transform.parent = null;
//beingCarried = false;
//GetComponent<Rigidbody>().AddForce(playerCam.forward * throwForce);
//}
if (Input.GetMouseButtonDown(1))
{
beingCarried = false;
tekdondur.GetComponent<Rigidbody>().isKinematic = false;
tekdondur.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
tekdondur.transform.parent = null;
}
}
}
}