Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class pickupController : MonoBehaviour
- {
- bool canPickUp;
- bool carrying = false;
- GameObject player;
- GameObject obj;
- RaycastHit hit;
- Ray ray;
- [SerializeField]
- float range = 3f;
- bool holoActive = false;
- // Start is called before the first frame update
- void Start()
- {
- obj = this.transform.parent.gameObject;
- canPickUp = false;
- player = GameObject.FindGameObjectWithTag("Player");
- }
- // Update is called once per frame
- void Update()
- {
- if(canPickUp == true)
- {
- PickUp();
- }
- if(carrying == true)
- {
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit))
- {
- if (hit.transform.tag == "Surface" && Vector3.Distance(player.transform.position, hit.point) < range)
- {
- obj.transform.Find("holo").gameObject.SetActive(true);
- obj.transform.position = new Vector3(hit.point.x, hit.point.y + 0.5f, hit.point.z);
- }
- }
- }
- }
- private void OnTriggerEnter(UnityEngine.Collider other)
- {
- if (other.transform.tag == "Player")
- {
- canPickUp = true;
- }
- }
- private void OnTriggerExit(UnityEngine.Collider other)
- {
- if(other.transform.tag == "Player")
- {
- canPickUp = false;
- }
- }
- void PickUp()
- {
- canPickUp = false;
- carrying = true;
- obj.transform.GetComponent<Collider>().enabled = false;
- obj.transform.GetComponent<Rigidbody>().isKinematic = true;
- foreach (MeshRenderer mesh in obj.transform.GetComponentsInChildren<MeshRenderer>())
- {
- if (mesh.gameObject.name != "holo")
- {
- mesh.enabled = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement