TO SQUASH: Shark notifications.
This commit is contained in:
@@ -308,6 +308,8 @@ MonoBehaviour:
|
|||||||
hitSound: {fileID: 8300000, guid: 0535a1781b9d2e8018f56aa45b71932a, type: 3}
|
hitSound: {fileID: 8300000, guid: 0535a1781b9d2e8018f56aa45b71932a, type: 3}
|
||||||
player: {fileID: 0}
|
player: {fileID: 0}
|
||||||
gameBoardSpriteRenderer: {fileID: 0}
|
gameBoardSpriteRenderer: {fileID: 0}
|
||||||
|
notificationPrefab: {fileID: 6394082776706812922, guid: 5cb297a990ab535aa8ef2b8054c9db1b, type: 3}
|
||||||
|
canvas: {fileID: 0}
|
||||||
normalMaxSpeed: 2.5
|
normalMaxSpeed: 2.5
|
||||||
turnRateDegreesPerSecond: 180
|
turnRateDegreesPerSecond: 180
|
||||||
speedChangeRate: 4
|
speedChangeRate: 4
|
||||||
|
|||||||
@@ -462,6 +462,7 @@ MonoBehaviour:
|
|||||||
sharkPrefab: {fileID: 1185323843861964289, guid: 4bb45ba16a3bbd351a45d39c3f0b62f9, type: 3}
|
sharkPrefab: {fileID: 1185323843861964289, guid: 4bb45ba16a3bbd351a45d39c3f0b62f9, type: 3}
|
||||||
gameBoardSpriteRenderer: {fileID: 297740151}
|
gameBoardSpriteRenderer: {fileID: 297740151}
|
||||||
player: {fileID: 1002905792}
|
player: {fileID: 1002905792}
|
||||||
|
canvas: {fileID: 2071745861}
|
||||||
--- !u!1 &83016091
|
--- !u!1 &83016091
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class NotifierBase : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
public Canvas canvas;
|
||||||
|
|
||||||
|
public GameObject notificationPrefab;
|
||||||
|
|
||||||
|
protected GameObject notificationInstance;
|
||||||
|
|
||||||
|
|
||||||
|
protected void ShowNotification(string text)
|
||||||
|
{
|
||||||
|
if (notificationPrefab == null || canvas == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationInstance = Instantiate(notificationPrefab);
|
||||||
|
notificationInstance.transform.SetParent(canvas.transform, false);
|
||||||
|
notificationInstance.transform.localScale = Vector3.one;
|
||||||
|
|
||||||
|
var notificationRect = notificationInstance.GetComponent<RectTransform>();
|
||||||
|
var canvasRect = canvas.GetComponent<RectTransform>();
|
||||||
|
var label = notificationInstance.GetComponent<UnityEngine.UI.Text>();
|
||||||
|
|
||||||
|
if (label != null)
|
||||||
|
{
|
||||||
|
label.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notificationRect != null && canvasRect != null)
|
||||||
|
{
|
||||||
|
Camera worldCamera = canvas.worldCamera != null ? canvas.worldCamera : Camera.main;
|
||||||
|
Camera uiCamera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : worldCamera;
|
||||||
|
|
||||||
|
if (worldCamera != null)
|
||||||
|
{
|
||||||
|
Vector2 screenPoint = worldCamera.WorldToScreenPoint(transform.position);
|
||||||
|
|
||||||
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, uiCamera, out Vector2 localPoint))
|
||||||
|
{
|
||||||
|
notificationRect.anchoredPosition = localPoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StartCoroutine(HideNotification());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IEnumerator HideNotification()
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(1.5f);
|
||||||
|
|
||||||
|
if (notificationInstance != null)
|
||||||
|
{
|
||||||
|
Destroy(notificationInstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c976d582b8415504b9c7e375271452a2
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class Shark : MonoBehaviour
|
public class Shark : NotifierBase
|
||||||
{
|
{
|
||||||
public AudioClip spawnSound;
|
public AudioClip spawnSound;
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class Shark : MonoBehaviour
|
|||||||
|
|
||||||
private float angryProbability = 0.1f;
|
private float angryProbability = 0.1f;
|
||||||
|
|
||||||
private static int sharkKillPoints = 100;
|
private static int sharkKillPoints = 1000;
|
||||||
|
|
||||||
private bool spawnFinished = false;
|
private bool spawnFinished = false;
|
||||||
|
|
||||||
@@ -167,7 +167,17 @@ public class Shark : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
audioSource.PlayOneShot(deathSound);
|
audioSource.PlayOneShot(deathSound);
|
||||||
player.score += sharkKillPoints;
|
player.score += sharkKillPoints + (isAngry ? 500 : 0);
|
||||||
|
|
||||||
|
if (isAngry)
|
||||||
|
{
|
||||||
|
ShowNotification("1500");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowNotification("1000");
|
||||||
|
}
|
||||||
|
|
||||||
StartCoroutine(DestroyShark());
|
StartCoroutine(DestroyShark());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ public class SharkSpawner : Spawner
|
|||||||
|
|
||||||
public Player player;
|
public Player player;
|
||||||
|
|
||||||
|
public Canvas canvas;
|
||||||
|
|
||||||
private Bounds gameBoardBounds;
|
private Bounds gameBoardBounds;
|
||||||
|
|
||||||
private float spawnTimer = 0f;
|
private float spawnTimer = 0f;
|
||||||
@@ -30,7 +32,7 @@ public class SharkSpawner : Spawner
|
|||||||
{
|
{
|
||||||
spawnTimer += Time.fixedDeltaTime;
|
spawnTimer += Time.fixedDeltaTime;
|
||||||
|
|
||||||
if (spawnTimer >= 1f && isActive && isSpawning && player.level >= 10)
|
if (spawnTimer >= 1f && isActive && isSpawning && player.level >= 1)
|
||||||
{
|
{
|
||||||
spawnTimer = 0f;
|
spawnTimer = 0f;
|
||||||
if (Random.value < spawnProbability)
|
if (Random.value < spawnProbability)
|
||||||
@@ -39,6 +41,7 @@ public class SharkSpawner : Spawner
|
|||||||
Shark sharkScript = shark.GetComponent<Shark>();
|
Shark sharkScript = shark.GetComponent<Shark>();
|
||||||
sharkScript.gameBoardSpriteRenderer = gameBoardSpriteRenderer;
|
sharkScript.gameBoardSpriteRenderer = gameBoardSpriteRenderer;
|
||||||
sharkScript.player = player;
|
sharkScript.player = player;
|
||||||
|
sharkScript.canvas = canvas;
|
||||||
isActive = false;
|
isActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public abstract class YummyBase : MonoBehaviour
|
public abstract class YummyBase : NotifierBase
|
||||||
{
|
{
|
||||||
public AudioClip bounceSound;
|
public AudioClip bounceSound;
|
||||||
|
|
||||||
@@ -9,12 +9,6 @@ public abstract class YummyBase : MonoBehaviour
|
|||||||
|
|
||||||
public AudioClip missedSound;
|
public AudioClip missedSound;
|
||||||
|
|
||||||
public Canvas canvas;
|
|
||||||
|
|
||||||
public GameObject notificationPrefab;
|
|
||||||
|
|
||||||
protected GameObject notificationInstance;
|
|
||||||
|
|
||||||
private AudioSource audioSource;
|
private AudioSource audioSource;
|
||||||
|
|
||||||
private Animator animator;
|
private Animator animator;
|
||||||
@@ -119,53 +113,4 @@ public abstract class YummyBase : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void ObtainedCallback(Player player);
|
protected abstract void ObtainedCallback(Player player);
|
||||||
|
|
||||||
protected void ShowNotification(string text)
|
|
||||||
{
|
|
||||||
if (notificationPrefab == null || canvas == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
notificationInstance = Instantiate(notificationPrefab);
|
|
||||||
notificationInstance.transform.SetParent(canvas.transform, false);
|
|
||||||
notificationInstance.transform.localScale = Vector3.one;
|
|
||||||
|
|
||||||
var notificationRect = notificationInstance.GetComponent<RectTransform>();
|
|
||||||
var canvasRect = canvas.GetComponent<RectTransform>();
|
|
||||||
var label = notificationInstance.GetComponent<UnityEngine.UI.Text>();
|
|
||||||
|
|
||||||
if (label != null)
|
|
||||||
{
|
|
||||||
label.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notificationRect != null && canvasRect != null)
|
|
||||||
{
|
|
||||||
Camera worldCamera = canvas.worldCamera != null ? canvas.worldCamera : Camera.main;
|
|
||||||
Camera uiCamera = canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : worldCamera;
|
|
||||||
|
|
||||||
if (worldCamera != null)
|
|
||||||
{
|
|
||||||
Vector2 screenPoint = worldCamera.WorldToScreenPoint(transform.position);
|
|
||||||
|
|
||||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, uiCamera, out Vector2 localPoint))
|
|
||||||
{
|
|
||||||
notificationRect.anchoredPosition = localPoint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StartCoroutine(HideNotification());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IEnumerator HideNotification()
|
|
||||||
{
|
|
||||||
yield return new WaitForSeconds(1.5f);
|
|
||||||
|
|
||||||
if (notificationInstance != null)
|
|
||||||
{
|
|
||||||
Destroy(notificationInstance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user