Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Helper;
- public class ZoneScript : BaseGate {
- Color makeTransparent = new Color(0f, 0f, 0f, -0.5f);
- public bool StayActivated = false;
- public float StayActiveTime = 1f;
- float timer = 0f;
- public AnimationCurve Animaton;
- public LineRenderer LineR;
- Vector3[] Vertices;
- public Transform Electron;
- float Radius = 2F;
- float minRadius = 2f;
- float maxRadius = 3f;
- Vector2 ElectronPos;
- float ElectronSpeed = 1f;
- float minSpeed = 1f;
- float maxSpeed = 8f;
- float someVelocityThing = 1f;
- bool Rising = true;
- const float twoPi = Mathf.PI * 2f;
- void SwapMyColor()
- {
- myRend.color = Active ? Color.red + makeTransparent : Color.blue + makeTransparent;
- }
- SpriteRenderer myRend;
- void Awake()
- {
- CheckForReAssignment = false;
- myRend = GetComponent<SpriteRenderer>();
- //ActivationEvent += SwapMyColor;
- //DeActivationEvent += SwapMyColor;
- myRend.color = Color.red + makeTransparent;
- Vertices = new Vector3[128];
- LineR.material = new Material(Shader.Find("Sprites/Default"));
- }
- void Update()
- {
- someVelocityThing += Time.deltaTime * ElectronSpeed;
- ElectronPos = (Vector2) transform.position + new Vector2(Mathf.Cos(someVelocityThing), Mathf.Sin(someVelocityThing)) * Radius;
- Electron.position = ElectronPos;
- if(!StayActivated && Active)
- {
- if(timer < 0.5f)
- timer += Time.deltaTime;
- else
- {
- timer = 0.5f;
- }
- float val = LerpFunctions.Remap(timer, 0f, 0.5f, 0f, 1f);
- float crvEval = Animaton.Evaluate(val);
- ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
- Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
- float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
- for (int i = 0; i < 128; ++i)
- {
- float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
- Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
- }
- LineR.SetPositions(Vertices);
- }
- else if(!StayActivated && !Active)
- {
- if(timer > 0f)
- {
- timer -= Time.deltaTime;
- }
- else
- {
- timer = 0f;
- }
- float val = LerpFunctions.Remap(timer, 0f, 0.5f, 0f, 1f);
- float crvEval = Animaton.Evaluate(val);
- ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
- Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
- float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
- for(int i = 0; i < 128; ++i)
- {
- float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
- Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
- }
- LineR.SetPositions(Vertices);
- }
- if(StayActivated && Active && Rising)
- {
- timer += Time.deltaTime;
- float val = LerpFunctions.Remap(timer, 0f, StayActiveTime, 0f, 1f);
- float crvEval = Animaton.Evaluate(val);
- ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
- Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
- float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
- for (int i = 0; i < 128; ++i)
- {
- float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
- Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
- }
- LineR.SetPositions(Vertices);
- if (timer >= StayActiveTime)
- {
- Rising = false;
- }
- }
- else if(Active && StayActivated && !Rising)
- {
- timer -= Time.deltaTime;
- float val = LerpFunctions.Remap(timer, 0f, StayActiveTime, 0f, 1f);
- float crvEval = Animaton.Evaluate(val);
- ElectronSpeed = Mathf.Lerp(minSpeed, maxSpeed, crvEval);
- Radius = Mathf.Lerp(minRadius, maxRadius, crvEval);
- float remapPi = LerpFunctions.Remap(crvEval, 0f, 1f, 0.2f * twoPi, 0.8f * twoPi);
- for (int i = 0; i < 128; ++i)
- {
- float currentTime = someVelocityThing - i * 1f / 128f * remapPi;
- Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
- }
- LineR.SetPositions(Vertices);
- if (timer <= 0f)
- {
- timer = 0f;
- Active = false;
- Rising = true;
- }
- }
- else if(Rising && StayActivated && !Active && timer == 0f)
- {
- for (int i = 0; i < 128; ++i)
- {
- float currentTime = someVelocityThing - i * 1f / 128f * 0.2f * twoPi;
- Vertices[i] = transform.position + new Vector3(Mathf.Cos(currentTime), Mathf.Sin(currentTime), 0f) * Radius;
- }
- LineR.SetPositions(Vertices);
- }
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- if (Sleeping) return;
- if (other.gameObject.layer == Hero.INACTIVE) return;
- if (Active) return;
- if (IInteractWith == 0)
- {
- Active = true;
- }
- else
- {
- if ((int)IInteractWith == other.gameObject.layer)
- {
- Active = true;
- }
- }
- }
- void OnTriggerExit2D(Collider2D other)
- {
- if (Sleeping) return;
- if (other.gameObject.layer == Hero.INACTIVE) return;
- if (StayActivated) return;
- if (IInteractWith == 0)
- {
- Active = false;
- }
- else
- {
- if ((int)IInteractWith == other.gameObject.layer)
- {
- Active = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement