I can pickup object, but i Can!t throw it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickupNewScript : MonoBehaviour
{
private Transform cubeTransform;
private bool IsTextDisabled;
public GameObject PickupObjectText;
public GameObject ThrowObjectText;
// Start is called before the first frame update
void Start()
{
cubeTransform = GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
GameObject GameOBJ = GameObject.Find("GAME");
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100f))
{
if (hit.transform == cubeTransform && (transform.position - Camera.main.transform.position).magnitude < 2.0f)
{
if (gameObject.transform.parent.gameObject.name == "KameraHrac1")
{
PickupObjectText.SetActive(false);
ThrowObjectText.SetActive(true);
if (Input.GetKeyDown(KeyCode.E) && gameObject.transform.parent.gameObject.name == "GAME")
{
gameObject.transform.parent = GameOBJ.transform;
}
}
if (gameObject.transform.parent.gameObject.name == "GAME")
{
PickupObjectText.SetActive(true);
ThrowObjectText.SetActive(false);
IsTextDisabled = false;
if (Input.GetKeyDown(KeyCode.E))
{
gameObject.transform.parent = Camera.main.transform;
}
}
}
else
{
if (IsTextDisabled == false)
{
PickupObjectText.SetActive(false);
IsTextDisabled = true;
}
}
}
}
}