예제 #1
0
        void Update()
        {
            if (building_mode && building_character != null)
            {
                PlayerControls      constrols = PlayerControls.Get(building_character.player_id);
                PlayerControlsMouse mouse     = PlayerControlsMouse.Get();

                if (!position_set)
                {
                    if (constrols.IsGamePad())
                    {
                        //Controller Game Pad building
                        transform.position = building_character.transform.position + building_character.transform.forward * build_distance;
                        transform.rotation = Quaternion.Euler(0f, manual_rotate, 0f) * Quaternion.LookRotation(building_character.GetFacing(), Vector3.up);
                    }
                    else
                    {
                        //Mouse/Touch controls
                        transform.position = mouse.GetPointingPos();
                        transform.rotation = Quaternion.Euler(0f, manual_rotate, 0f) * TheCamera.Get().GetFacingRotation();
                    }

                    //Snap to grid
                    FindAutoPosition();

                    //Show/Hide on mobile
                    if (TheGame.IsMobile())
                    {
                        SetBuildVisible(mouse.IsMouseHold());
                    }
                }

                bool  can_build = CheckIfCanBuild();
                Color color     = can_build ? Color.white : Color.red * 0.9f;
                SetModelColor(new Color(color.r, color.g, color.b, 0.5f), !can_build);
            }

            update_timer += Time.deltaTime;
            if (update_timer > 0.5f)
            {
                update_timer = Random.Range(-0.02f, 0.02f);
                SlowUpdate(); //Optimization
            }
        }