PublicVoidPoop
9/11/2019 - 1:09 AM

ScriptableObject

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;



[System.Serializable]
public class TopScrollInfoText : ScriptableObject
{
  ScrollTextBehavior ScrollTextBehavior;

  [Header("Text Component Settings")]
  public Text Text;
  public string ScrollingText;
  [Space(15f)]
  [ColorUsage(true, true, 0, 1, 0, 1)]
  public Color Color;

  [Range(0f, 1f)]
  public float RChannel;
  [Range(0f, 1f)]
  public float GChannel;
  [Range(0f, 1f)]
  public float BChannel;
  [Space(15f)]

  [Header("Scroll Positions")]

  public RectTransform beginScroll;
  public RectTransform endScroll;
  public float speed;


 




 

  void OnEnable()
  {
    ScrollTextBehavior = FindObjectOfType<ScrollTextBehavior>();
    Color.a = 1f;
    
  }

  void Awake()
  {
   
   
   
  }

  void RandomChannelSet()
  {
    RChannel = Random.Range(0f, 1.0f);
    GChannel = Random.Range(0f, 1.0f);
    BChannel = Random.Range(0f, 1.0f);

  }

  public  IEnumerator ColorChange()
  {
    RandomChannelSet();
    bool goingUp = true;
    //  bool goindDown;
    while (true)
      {

        if (RChannel >= 1 && GChannel >= 1 || RChannel >= 1 && BChannel >= 1 || BChannel >= 1 && GChannel >= 1)
          {
            //RandomChannelSet();
            goingUp = false;

          } else if (RChannel <= 0 && GChannel <= 0 || RChannel <= 0 && BChannel <= 0 || BChannel <= 0 && GChannel <= 0)
          {
            // RandomChannelSet();
            goingUp = true;
          }

        if (goingUp == false)
          {
            while (RChannel >= 0f)
              {
                float x = Random.Range(0f, .09f);
                RChannel -= x;
                Color.r = RChannel;

                break;
              }
            while (GChannel >= 0f)
              {
                float x = Random.Range(0f, .09f);
                GChannel -= x;
                Color.g = GChannel;

                break;
              }
            while (BChannel >= 0f)
              {
                float x = Random.Range(0f, .09f);
                BChannel -= x;
                Color.b = BChannel;

                break;
              }

          }
        if (goingUp)
          {
            while (RChannel <= 1f)
              {
                RChannel += .03f;
                Color.r = RChannel;
           
                break;
              }
            while (GChannel <= 1f)
              {
                GChannel += .03f;
                Color.g = GChannel;
           
                break;
              }
            while (BChannel <= 1f)
              {
                BChannel += .03f;
                Color.b = BChannel;
            
                break;
              }
          }
        RChannel = Color.r;
        GChannel = Color.g;
        BChannel = Color.b;
        

        yield return new WaitForSeconds(.1f);
      }
    
  }

 
      
      
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;


public class ScrollTextBehavior : MonoBehaviour
{
  [TextArea(2, 2)]
  public  string LookFor = "Edit this component with the TopScrollInfoText Scriptable Object";

  TopScrollInfoText Info;
  Text thisText;
  RectTransform begin, end;

  float speed;

  public void SetUp()
  {
    Info = ScriptableObjectManager._instance.TopScrollInfoText;
    thisText = gameObject.GetComponentInChildren<Text>();
   

    begin = Info.beginScroll;
    end = Info.endScroll;
    thisText.rectTransform.localPosition = begin.localPosition;
     
    Debug.Log("SetUp Called");
  }

  void Start()
  {
   
    SetUp();
    StartCoroutine(Info.ColorChange());
 
  }

  void ScrollText()
  {
   
    Vector3 pos = new Vector3(end.localPosition.x, thisText.rectTransform.localPosition.y, 0);
    speed = Info.speed;
    thisText.color = Info.Color;
    thisText.text = Info.ScrollingText;
   
    if (thisText.rectTransform.localPosition.x > pos.x)
      {
        thisText.rectTransform.Translate(Vector3.left * speed * Time.fixedDeltaTime);
      } else
      {

        thisText.rectTransform.localPosition = begin.localPosition;

      }
  }


  void FixedUpdate()
  {
    ScrollText();

  }

 

}