void pickup() { if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2")) { int x = Screen.width / 2; int y = Screen.height / 2; Ray ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(new Vector3(x, y)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Pickupable p = hit.collider.GetComponent <Pickupable>(); PickupableAn z = hit.collider.GetComponent <PickupableAn> (); PickupableBer q = hit.collider.GetComponent <PickupableBer>(); if (p != null) { carrying = true; carriedObject = p.gameObject; p.gameObject.GetComponent <Rigidbody>().isKinematic = true; } else if (z != null) { carrying = true; carriedObject = z.gameObject; z.gameObject.GetComponent <Rigidbody>().isKinematic = true; } else if (q != null) { carrying = true; carriedObject = q.gameObject; q.gameObject.GetComponent <Rigidbody>().isKinematic = true; } } } }
IEnumerator ambil1() { yield return(new WaitForSeconds(angka)); int x = Screen.width / 2; int y = Screen.height / 2; Ray ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(new Vector3(x, y)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Pickupable p = hit.collider.GetComponent <Pickupable>(); PickupableAn z = hit.collider.GetComponent <PickupableAn> (); PickupableBer q = hit.collider.GetComponent <PickupableBer>(); if (p != null) { carrying = true; carriedObject = p.gameObject; p.gameObject.GetComponent <Rigidbody>().isKinematic = true; } else if (z != null) { carrying = true; carriedObject = z.gameObject; z.gameObject.GetComponent <Rigidbody>().isKinematic = true; } else if (q != null) { carrying = true; carriedObject = q.gameObject; q.gameObject.GetComponent <Rigidbody>().isKinematic = true; } } }