Esempio n. 1
0
        /// <summary>
        /// Instantiate a new instance of the floating text class using the supplied parameters
        /// </summary>
        /// <param name="prefab">The prefab to use as the base</param>
        /// <param name="canvas">The UI canvas to use for parenting</param>
        /// <param name="start">The start location</param>
        /// <param name="text">The text to display</param>
        /// <returns>The new floating text instance</returns>
        public static FloatingUIText Create(FloatingUIText prefab, Canvas canvas, Vector3 start, string text)
        {
            FloatingUIText ft = GameObject.Instantiate <FloatingUIText>(prefab);

            ft.transform.SetParent(canvas.transform, false);
            ft.transform.position = start;
            ft.textComponent      = ft.GetComponent <Text>();
            ft.textComponent.text = text;

            if (canvas.renderMode == RenderMode.WorldSpace)
            {
                ft.transform.localScale *= ft.WorldScale;
            }

            return(ft);
        }
Esempio n. 2
0
        void OnTriggerEnter2D(Collider2D other)
        {
            // Just destroy the object when collected to give you an idea of what sort of features you could add to a game like this.
            Character c = other.GetComponent <Character>();

            if (c != null)
            {
                // For screen overlay camera's we need to calculate the new posision
                Vector3 titlePosition = c.transform.position + (Vector3.up * 1.5f);
                if (SurvivalCollectable.uiCanvas.renderMode == RenderMode.ScreenSpaceOverlay)
                {
                    titlePosition = Camera.main.WorldToScreenPoint(titlePosition);
                }

                // Add some floating text to show the item name
                string text = "Log x1";
                var    ft   = FloatingUIText.Create(this.CollectTextPrefab, SurvivalCollectable.uiCanvas, titlePosition, text);
                ft.WaveDistance = 0;

                GameObject.Destroy(this.gameObject);
            }
        }
        void OnTriggerEnter2D(Collider2D other)
        {
            // Just destroy the object when collected to give you an idea of what sort of features you could add to a game like this.
            Character c = other.GetComponent <Character>();

            if (c != null)
            {
                // Find the canvas the first time we need it and cache it for all future uses
                if (PlatformerCollectable.uiCanvas == null)
                {
                    PlatformerCollectable.uiCanvas = FindObjectOfType <Canvas>();
                }

                // Add some floating text to show the item name
                Vector3 titlePosition = c.transform.position + (Vector3.up * 1.5f);
                string  text          = "+" + this.ScoreValue;
                var     ft            = FloatingUIText.Create(this.CollectTextPrefab, PlatformerCollectable.uiCanvas, titlePosition, text);
                ft.WaveDistance = 0;

                GameObject.Destroy(this.gameObject);
            }
        }
Esempio n. 4
0
        private void SelectCharacter(int index)
        {
            if (index >= 0 && index < this.Characters.Length)
            {
                Vector3             position  = new Vector3();
                Character.Direction direction = Character.Direction.Right;
                if (this.selectedCharacter != null)
                {
                    // Remove previous character
                    position  = this.selectedCharacter.transform.position;
                    direction = this.selectedCharacter.CurrentDirection;
                    GameObject.Destroy(this.selectedCharacter.gameObject);
                }
                else if (this.SpawnPlayerPoint != null)
                {
                    position = this.SpawnPlayerPoint.position;
                }

                // Spawn new character
                this.selectedCharacter = GameObject.Instantiate <Character>(this.Characters[this.selectedIndex], position, Quaternion.identity, null);
                this.selectedCharacter.ForceDirection(direction);

                // Add some floating text to show the character name
                Vector3 titlePosition = this.selectedCharacter.transform.position + (Vector3.up * 1.5f);
                string  text          = this.selectedCharacter.name.Replace("_", " ").Replace(" Variant", "").Replace("(Clone)", "");
                FloatingUIText.Create(this.TitleTextPrefab, this.UICanvas, titlePosition, text);

                SimpleFollowCamera cam = Camera.main.GetComponent <SimpleFollowCamera>();
                if (cam != null)
                {
                    cam.FollowTarget = this.selectedCharacter.transform;
                }

                if (this.OnSelectedCharacterChanged != null)
                {
                    this.OnSelectedCharacterChanged.Invoke(this.selectedCharacter);
                }
            }
        }