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); } }
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); } }
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); } } }