bool TransferPackage(RopeManager.Rope rope) { foreach (GameObject packageObj in GameObject.FindGameObjectsWithTag("Package")) { Package package = packageObj.GetComponent <Package>(); if (package.ropeTransfer == null && package.hookedTo == rope.from.transform) { rope.from.isConnected--; rope.to.isConnected++; package.hookedTo = rope.to.transform; package.ropeTransfer = rope; rope.inTransfer++; if (rope.inTransfer == 1) { rope.lineRenderer.GetComponent <RopeColor>().Transfer(); AudioManager.GunFired(); } return(true); } } return(false); }
void Update() { if (!pInput.IsActive()) { return; } if (pInput.IsActing()) { isActing = true; } if (isActing) { RopeManager.Rope closestRope = pInput.ropeManager.GetClosestRope(transform.position, maxDistance); if (!pInput.IsActing()) { isActing = false; if (prevSelected) { prevSelected.ResetColor(); prevSelected = null; } if (closestRope != null) { TransferPackage(closestRope); } } else { if (closestRope != null) { RopeColor selected = closestRope.lineRenderer.GetComponent <RopeColor>(); if (prevSelected != selected) { if (prevSelected) { prevSelected.ResetColor(); } prevSelected = selected; prevSelected.Highlight(); } } else if (prevSelected) { prevSelected.ResetColor(); prevSelected = null; } } } }
void Update() { float distanceToTarget = Vector3.Distance(transform.position, hookedTo.position); if (distanceToTarget > rotateDistance) { Vector3 moveDir = (hookedTo.position - transform.position).normalized; transform.position += moveDir * Mathf.Min(moveSpeed * Time.deltaTime, distanceToTarget); } else { transform.RotateAround(hookedTo.position, Vector3.forward, rotateSpeed * Time.deltaTime); if (movingToEnd) { if (movingToEndTime <= 0.0f) { terminal.RemovePackage(packageType); Destroy(gameObject); } else { movingToEndTime -= Time.deltaTime; if (movingToEndTime <= 0.0f) { hookedTo = movingToEnd.endPoint; movingToEnd.IncreaseData(); } } } else if (ropeTransfer != null) { EndCentre endCentre = ropeTransfer.to as EndCentre; if (endCentre && endCentre.packageType == packageType) { movingToEnd = endCentre; } else { inTransfer = false; } ropeTransfer.inTransfer--; if (ropeTransfer.inTransfer == 0) { ropeTransfer.lineRenderer.GetComponent <RopeColor>().ResetTransfer(); } ropeTransfer = null; } } }