Example #1
0
    public void AddPlacer(bool isPlayer, string playerName)
    {
        GameObject   newPlacer    = Instantiate(placerPrefab) as GameObject;
        IslandPlacer islandPlacer = newPlacer.GetComponent <IslandPlacer>();

        islandPlacer.transform.SetParent(worldAnchor);

        islandPlacer.transform.localRotation = Quaternion.identity;

        islandPlacer.Init(playerName, isPlayer);

        if (!isPlayer)
        {
            multiplayer.AddIslandListener(playerName, islandPlacer.GetNetworkUpdate);
        }
    }
    void Update()
    {
        if (!isVisible)
        {
            return;
        }

        if (!isComplete && visibleAmount <= 1.0f)
        {
            visibleAmount += Time.deltaTime / 0.5f;
            float amount = Mathf.SmoothStep(0, 1, visibleAmount);
            transform.localScale = Vector3.Lerp(Vector3.one * 0.1f, Vector3.one, amount);
        }

        if (isComplete)
        {
            visibleAmount -= Time.deltaTime / 0.5f;
            float amount = Mathf.SmoothStep(0, 1, visibleAmount);
            transform.localScale = Vector3.Lerp(Vector3.one * 0.1f, Vector3.one, amount);
            if (visibleAmount < 0.1f)
            {
                Destroy(gameObject);
            }
            return;
        }

        if (isPlayer)
        {
            updateTimer -= Time.deltaTime;
            if (updateTimer < 0)
            {
                updateTimer = 1.0f;
                PostSettings();
            }
        }


        if (!opponentPlacer)
        {
            GameObject[] placers = GameObject.FindGameObjectsWithTag("IslandPlacer");
            foreach (var placer in placers)
            {
                if (!placer.Equals(gameObject))
                {
                    opponentPlacer = placer.GetComponent <IslandPlacer>();
                }
            }
        }

        if (opponentPlacer)
        {
            float distance = Vector3.Distance(transform.position, opponentPlacer.transform.position);
            if (distance > 0.1f)
            {
                transform.LookAt(opponentPlacer.transform, transform.parent.up);
                Vector3 opponentPos = opponentPlacer.transform.position;
                opponentPos.y = 0;
                Vector3 myPos = transform.position;
                myPos.y            = 0;
                transform.rotation = Quaternion.LookRotation(opponentPos - myPos);
            }

            TooClose = distance < minDistance;
            if (isPlayer && isReady && opponentPlacer.IsReady)
            {
                Place();
            }
        }

        messageBox.transform.rotation = Quaternion.LookRotation(messageBox.transform.position - Camera.main.transform.position);

        if (messageTimer > 0)
        {
            messageTimer -= Time.deltaTime;
            if (messageTimer < 0)
            {
                messageBox.SetActive(false);
            }
        }
    }