spinningcube/Assets/Scripts/PopupNotification.cs
Shaun M Reed 1bcca0e925 Reworked (bad)notification system
- Reduced huge amount of fluff logic, loops, conditionals
- Fixed infinite loop within 4+ calls to SendNotification()
-- Replaced with new function MakePopup(string contents)
-- Spawns a prefab, can call as much as you want (overlapping issue)
-Add combining of colliding Popups with similar contents (exp)
-- Add a tag passed into MakePopup() as argument used to combine similar
values ( and increase time left to Destroy(), raise speed of transform
to move away from other popups)
- Popups rotate within a range of -4 to 4 for trendy not-perfect look
*shrug*
2017-09-05 18:12:08 -04:00

50 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PopupNotification : MonoBehaviour {
public bool active = false;
public Vector3 origin;
public float timer = 0.0f;
public string localNotify;
// Use this for initialization
void OnEnable ()
{
active = true;
double randomRotation = GetRandomNumber(-4.0, 4.0);
transform.Rotate(0.0f, 0.0f, (float)randomRotation);
Debug.Log("Rotation set to :" + randomRotation);
origin = this.transform.localPosition;
localNotify = GameObject.Find("EventSystem").GetComponent<GameManager>().GetNotify();
}
// Update is called once per frame
void FixedUpdate()
{
timer += 0.02f;
this.gameObject.transform.Translate(new Vector3(0, 50f * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
if (timer >= 3)
{
active = false;
timer = 0.0f;
Destroy(this.gameObject);
}
}
public double GetRandomNumber(double min, double max)
{
System.Random random = new System.Random();
return random.NextDouble() * (max - min) + min;
}
}