コード例 #1
0
    private void PerformMove()
    {
        if (shouldCheck == false || isMoving || currentTransmitter.IsMoving)
        {
            return;
        }

        if (currentTransmitter.HasConnections)
        {
            if (previousTransmitter != null)
            {
                breakCount += Time.deltaTime;

                if (breakCount >= timeBeforeBreak)
                {
                    breakCount = 0f;
                    previousTransmitter.RemoveSpark();
                    previousTransmitter = null;
                }
            }

            List <GameObject> connectedPieces = currentTransmitter.GetConnectedPieces();

            for (int i = 0; i < connectedPieces.Count; i++)
            {
                Vector3    rayOrigin = connectedPieces[i].transform.position + connectedPieces[i].transform.forward;
                Ray        ray       = new Ray(rayOrigin, connectedPieces[i].transform.forward);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, map.nodeSpacing, transmitterMask))
                {
                    Transmitter t = hit.transform.GetComponentInParent <Transmitter>();

                    if (t == null || t == previousTransmitter)
                    {
                        continue;
                    }

                    StartCoroutine(Move(t));
                    shouldCheck = false;

                    currentTransmitter.RemoveSpark();
                    previousTransmitter = currentTransmitter;
                    currentTransmitter  = t;
                    currentTransmitter.GiveSpark(this);
                    transmitterController.UpdateConnections();

                    return;
                }
            }
        }
    }
コード例 #2
0
 public void GiveTransmitter(Transmitter transmitter)
 {
     currentTransmitter = transmitter;
     currentTransmitter.GiveSpark(this);
 }