コード例 #1
0
    public IEnumerator attachCreature()
    {
        tempBack = mainHead.GetComponent <EnemyHead>().back;
        if (tempBack != null)
        {
            for (int i = 0; i < 50; i++)
            {
                if (tempBack.GetComponent <EnemyBack>().back != null)
                {
                    if (tempBack.GetComponent <EnemyBack>().back.GetComponent <EnemyTail>() != null)
                    {
                        tempTail = tempBack.GetComponent <EnemyBack>().back;
                        break;
                    }
                    tempBack = tempBack.GetComponent <EnemyBack>().back;
                }
                else
                {
                    break;
                }
            }
        }
        attachingCreature = true;
        yield return(new WaitForSeconds(0.8f));

        tempBack.GetComponent <EnemyBack>().back = back;
        back.GetComponent <EnemyBack>().front    = tempBack;
        TailPool.goInPool(tempTail);
        HeadPool.goHeadInPool(gameObject);
    }
コード例 #2
0
    void Update()
    {
        if (player == null)
        {
            player = GameObject.Find("Player");
        }

        //Логика движения змеи

        if (!secondaryHead)
        {
            if (firstStart)
            {
                if (transform.position != startPoint)
                {
                    transform.position = Vector3.MoveTowards(transform.position, startPoint, Time.deltaTime * speed);
                }
                else
                {
                    firstStart = false;
                }
            }
            else
            {
                if (isPlayerOnTarget)
                {
                    transform.position = Vector3.MoveTowards(transform.position, player.transform.position, Time.deltaTime * speed);
                    pointOnCircle      = randomPiontOnCircle();
                    direction          = new Vector3(pointOnCircle.x, pointOnCircle.y, 0f);
                }
                else
                {
                    if (Mathf.Abs(transform.position.x) >= Mathf.Abs(screenSize.x) || Mathf.Abs(transform.position.y) >= Mathf.Abs(screenSize.y))
                    {
                        if (Mathf.Abs(transform.position.x) >= Mathf.Abs(screenSize.x))
                        {
                            direction = new Vector3(-direction.x, randomPiontOnCircle().y, 0f);
                            transform.Translate(direction * Time.deltaTime * speed);
                            if (Mathf.Abs(transform.position.x) >= Mathf.Abs(screenSize.x))
                            {
                                transform.Translate(direction * Time.deltaTime * speed);
                                if (Mathf.Abs(transform.position.y) >= Mathf.Abs(screenSize.x))
                                {
                                    isPlayerOnTarget = true;
                                }
                            }
                        }
                        if (Mathf.Abs(transform.position.y) >= Mathf.Abs(screenSize.y))
                        {
                            direction = new Vector3(randomPiontOnCircle().x, -direction.y, 0f);
                            transform.Translate(direction * Time.deltaTime * speed);
                            if (Mathf.Abs(transform.position.y) >= Mathf.Abs(screenSize.x))
                            {
                                transform.Translate(direction * Time.deltaTime * speed);
                                if (Mathf.Abs(transform.position.y) >= Mathf.Abs(screenSize.x))
                                {
                                    isPlayerOnTarget = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        transform.Translate(direction * Time.deltaTime * speed);
                    }
                }

                if (back == null)
                {
                    HeadPool.goHeadInPool(gameObject);
                }
            }
        }
        else
        {
            tempBack = mainHead.GetComponent <EnemyHead>().back;
            if (tempBack != null)
            {
                for (int i = 0; i < 50; i++)
                {
                    if (tempBack.GetComponent <EnemyBack>().back != null)
                    {
                        if (tempBack.GetComponent <EnemyBack>().back.GetComponent <EnemyTail>() != null)
                        {
                            tempTail = tempBack.GetComponent <EnemyBack>().back;
                            break;
                        }
                        tempBack = tempBack.GetComponent <EnemyBack>().back;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            transform.position = Vector3.MoveTowards(transform.position, tempBack.transform.position, Time.deltaTime * speed * 1.5f);
            if (!attachingCreature)
            {
                StartCoroutine(attachCreature());
            }
        }

        if (back.GetComponent <EnemyBack>().front != gameObject)
        {
            HeadPool.goHeadInPool(gameObject);
        }

        //Логика скорости
        if (System.Math.Round(score.score) % 10 == 0 && score.score > tempscore)
        {
            Debug.Log("+ Speed");
            speed     += 0.05f / GameObject.FindGameObjectsWithTag("EnemyHead").Length;
            tempscore += 10;
        }
    }