public void CollectDataFromConsole() { DataConsole dc = target.GetComponent <DataConsole>(); if (collectTime > collectCooldown) { if (dc != null && dc.CollectData(antennaTransform)) { collectTime = 0.0f; data.CollectData(1); } else { finishCollectingEvent.Invoke(); if (dc != null) { dc.CloseStream(antennaTransform); } collecting = false; target = null; collectionPoint = null; } } }
public void SetTarget(Transform newTarget) { DataConsole dc = target.GetComponent <DataConsole>(); if (dc) { dc.CloseStream(antennaTransform); } target = newTarget; collectionPoint = newTarget; foundTargetEvent.Invoke(); }
// Update is called once per frame void Update() { if (target == null) { GetNearestDataConsole(); } else if (target != null && Vector3.Distance(target.position, this.transform.position) < collectRange) { if (collecting) { CollectDataFromConsole(); } else { collecting = true; collectDataEvent.Invoke(); if (target.GetComponent <DataConsole>()) { target.GetComponent <DataConsole>().StartStream(antennaTransform); } } } else { this.transform.LookAt(target); } if (collecting && target && Vector3.Distance(target.position, this.transform.position) > collectRange) { DataConsole dc = target.GetComponent <DataConsole>(); collecting = false; if (dc) { dc.CloseStream(antennaTransform); } } collectTime += Time.deltaTime; }
public void PlayerCollectData() { if (Input.GetKey(InputManager.Instance.GetInteractKey()) && collectTime > collectCooldown) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { DataConsole dataConsole = hit.collider.transform.gameObject.GetComponent <DataConsole>(); float distance = Vector3.Distance(hit.transform.position, player.transform.position); if (distance <= collectRange) { if (dataConsole && dataConsole.CollectData(dataCollectPoint)) { collectTime = 0.0f; data.CollectData(1); // Debug.Log("CollectData"); } } } } }