Tukyo

NeonColor

May 23rd, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. ONSTART COLOR SET
  3. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  4.  
  5. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  6. THESE SCRIPTS (CHOOSE ONE) WILL ALLOW YOU TO CHOOSE THE COLOR OF A NEON COLOR AND SWITCH BETWEEN THE COLORS ONLY USING ONE MATERIAL IN YOUR SCENE! :D
  7.  
  8. FIRST SCRIPT "ONSTART" SETS THE COLOR OF THE NEON AT LAUNCH
  9.  
  10. SECOND SCRIPT WILL ALLOW YOU TO CHOOSE BETWEEN TWO COLORS AND MATH.PINGPONG BETWEEN THE VALUES AT YOUR DESIRED SPEED.
  11.  
  12. YOU CAN COMBINE BOTH OF THESE WITH AN OPTIONAL FLICKERING EFFECT!
  13. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  14.  
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. using UnityEngine;
  18.  
  19. public class NeonColor : MonoBehaviour
  20. {
  21. public Color neonColor = Color.white;
  22. public bool isFlickering = false;
  23. public float minFlickerAmount = 0.2f;
  24. public float maxFlickerAmount = 0.8f;
  25.  
  26. private Renderer objectRenderer;
  27. private MaterialPropertyBlock propertyBlock;
  28. private int flickeringID;
  29. private float flickerAmount;
  30.  
  31. private void Start()
  32. {
  33. objectRenderer = GetComponent<Renderer>();
  34. propertyBlock = new MaterialPropertyBlock();
  35. flickeringID = Shader.PropertyToID("_IsFlickering");
  36.  
  37. if (objectRenderer != null)
  38. {
  39. objectRenderer.GetPropertyBlock(propertyBlock);
  40. propertyBlock.SetColor("_NeonColor", neonColor);
  41. objectRenderer.SetPropertyBlock(propertyBlock);
  42. }
  43. }
  44.  
  45. private void Update()
  46. {
  47. if (isFlickering)
  48. {
  49. propertyBlock.SetFloat(flickeringID, 1f);
  50. flickerAmount = Random.Range(minFlickerAmount, maxFlickerAmount);
  51. propertyBlock.SetFloat("_FlickerAmount", flickerAmount);
  52. }
  53. else
  54. {
  55. propertyBlock.SetFloat(flickeringID, 0f);
  56. }
  57.  
  58. objectRenderer.SetPropertyBlock(propertyBlock);
  59. }
  60. }
  61.  
  62.  
  63. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  64. ONUPDATE COLOR CHANGING
  65. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  66.  
  67. using System.Collections;
  68. using System.Collections.Generic;
  69. using UnityEngine;
  70.  
  71. public class NeonColorChanging : MonoBehaviour
  72. {
  73. public Color neonColor = Color.white;
  74. public bool isFlickering = false;
  75. public float minFlickerAmount = 0.2f;
  76. public float maxFlickerAmount = 0.8f;
  77. public bool isColorChanging = false;
  78. public float colorChangeSpeed = 1.0f;
  79. public Color startColor = Color.white;
  80. public Color endColor = Color.red;
  81.  
  82. private Renderer objectRenderer;
  83. private MaterialPropertyBlock propertyBlock;
  84. private int flickeringID;
  85.  
  86. private void Start()
  87. {
  88. objectRenderer = GetComponent<Renderer>();
  89. propertyBlock = new MaterialPropertyBlock();
  90. flickeringID = Shader.PropertyToID("_IsFlickering");
  91.  
  92. if (objectRenderer != null)
  93. {
  94. objectRenderer.GetPropertyBlock(propertyBlock);
  95. objectRenderer.SetPropertyBlock(propertyBlock);
  96. }
  97. }
  98.  
  99. private void Update()
  100. {
  101. if (isFlickering)
  102. {
  103. // Code for flickering
  104. }
  105. else
  106. {
  107. propertyBlock.SetFloat(flickeringID, 0f); // Disable flickering
  108.  
  109. // Color changing
  110. if (isColorChanging)
  111. {
  112. float t = Mathf.PingPong(Time.time * colorChangeSpeed, 1f);
  113. neonColor = Color.Lerp(startColor, endColor, t);
  114. propertyBlock.SetColor("_NeonColor", neonColor);
  115. }
  116. }
  117.  
  118. objectRenderer.SetPropertyBlock(propertyBlock);
  119. }
  120.  
  121. private void OnValidate()
  122. {
  123. if (objectRenderer != null)
  124. {
  125. objectRenderer.GetPropertyBlock(propertyBlock);
  126. propertyBlock.SetColor("_NeonColor", neonColor);
  127. objectRenderer.SetPropertyBlock(propertyBlock);
  128. }
  129. }
  130. }
  131.  
  132. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  133. DOWNLOAD THIS SHADER AND USE THESE SCRIPTS TO COMMUNICATE WITH THE SHADER
  134.  
  135. https://drive.google.com/file/d/181ixxEi2Je-21L1E9bwbZXunsfifaVvL/view?usp=drive_link
  136. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Advertisement
Add Comment
Please, Sign In to add comment