Picking things up in unity
Hi all! I'm having a problem picking up items in Unity. I am using the standard fpscontroller from standard assets. I don't know how to make it so that when fpscontroller appears, give it the same text, button and other components. If you can, please help. Here is the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class collector : MonoBehaviour
{
public int inStock = 0;
public int MyNumber = 24;
public Text zadacha;
public Button mybutton;
RaycastHit hit;
public Text collectitems;
public GameObject items;
void Start()
{
mybutton.onClick.AddListener(MyVoid);
}
private void OnPhotonSynhronize(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(inStock);
}else if (stream.IsReading)
{
inStock = (int)stream.ReceiveNext();
}
}
void MyVoid()
{
if(hit.collider.tag == ("item"))
{
inStock += 1;
Destroy(hit.collider.gameObject);
}
}
void Update()
{
if (inStock == MyNumber)
{
Application.LoadLevel(6);
}
collectitems.text = inStock + "/" + MyNumber ;
if (Physics.Raycast(transform.position, transform.forward, out hit, 2f))
{
if (hit.collider.tag == ("item"))
{
mybutton.image.enabled = true;
}
else
{
mybutton.image.enabled = false;
}
}
else
{
mybutton.image.enabled = false;
}
}
}