示例#1
0
    // Update is called once per frame
    void Update()
    {
        switch (currentState)
        {
        case SerpentState.Tunnel:
            switch (tunnelState)
            {
            case TunnelState.Attack:
                head.position = Vector2.MoveTowards(head.position,
                                                    targetTransform.position, moveSpeed * Time.deltaTime);
                if (Vector3.Distance(head.position, targetTransform.position) < 0.1f)
                {
                    if (targetTransform.childCount > 0)
                    {
                        targetTransform = targetTransform.GetChild(0).transform;
                    }
                    else
                    {
                        tunnelState = TunnelState.Teleport;
                    }
                }
                break;

            case TunnelState.Search:
                RandomizeTarget();
                targetTransform = Tunnels[currentTunnel][Random.Range(0, 3)];
                head.gameObject.GetComponent <RotateToTarget>().SetTarget(targetTransform);
                tunnelState = TunnelState.Attack;
                break;

            case TunnelState.Teleport:
                RandomizeTarget();
                int t = Random.Range(0, 3);
                targetTransform = Tunnels[currentTunnel][t];
                head.position   = targetTransform.GetChild(0).position;
                serpentBody.Coil();
                tunnelState = TunnelState.Burrow;
                break;

            case TunnelState.Burrow:
                head.position = Vector2.MoveTowards(head.position,
                                                    targetTransform.position, moveSpeed * Time.deltaTime);
                if (Vector3.Distance(head.position, targetTransform.position) < 0.1f)
                {
                    tunnelState = TunnelState.Search;
                    StartCoroutine(StateWait());
                    currentState = SerpentState.Wait;
                }
                break;
            }
            break;

        case SerpentState.Bounce:
            break;

        case SerpentState.Wait:
            break;
        }
    }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        Tunnels[0]  = northTunnles;
        Tunnels[1]  = eastTunnles;
        Tunnels[2]  = southTunnles;
        Tunnels[3]  = westTunnles;
        serpentBody = GetComponentInChildren <SerpentBody>();
        head        = serpentBody.gameObject.transform.parent.transform;

        tunnelState = TunnelState.Teleport;
    }
 void Start()
 {
     playerPos       = GameObject.FindGameObjectWithTag("player").GetComponent <Transform>();
     lastPosSpawned += sectionLength / 2;
     for (int i = 0; i < maxSections; i++)
     {
         spawnNextSection();
     }
     a = tunnelStates[currentTunnelState];
     b = tunnelStates[currentTunnelState + 1];
     timeSinceStart = 0;
 }
示例#4
0
 public override void CommunicateWith(IPEndPoint remoteEndpoint)
 {
     if (State == TunnelState.Disconnected)
     {
         State          = TunnelState.SendingHello;
         RemoteEndPoint = remoteEndpoint;
         _socket.RegisterTunnel(this);
         SendPacket(MakeHelloPacket());
         State = TunnelState.WaitingForHelloResponse;
     }
     else
     {
         Debug.Fail("Cannot call \"CommunicateWith\" when out of the disconnected state");
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (playerPos.position.y + sectionLength < lastPosSpawned + (maxSections - 1.5) * sectionLength)
        {
            spawnNextSection();
        }

        if (playerPos.position.y < b.depth * max_depth)
        {
            currentTunnelState += 1;
            a = tunnelStates[currentTunnelState];
            b = tunnelStates[currentTunnelState + 1];
        }

        tunnelMat.Lerp(a.mat, b.mat, (playerPos.position.y - a.depth * max_depth) / (b.depth * max_depth - a.depth * max_depth));
        timeSinceStart += Time.deltaTime;
    }