Atomic_Violetta

Luigi Script

Mar 8th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | Gaming | 0 0
  1. //Luigi Script
  2. //name
  3.  
  4. using UnityEngine;
  5.  
  6. class LuigiScript : MonoBehaviour
  7. {
  8.  
  9. [SerializeField] private Color memberNormalColor = Color.green;
  10. [SerializeField] private Color memberBlueColor = Color.blue;
  11.  
  12. private SpriteRenderer memberSpriteRenderer = null;
  13. }
  14.  
  15.  
  16.  
  17.  
  18. // Update is called once per frame
  19. void Update()
  20. {
  21.  
  22. // Get the sprite renderer.
  23. memberSpriteRenderer = GetComponent<SpriteRenderer>();
  24.  
  25. // Vectors are variables that mean positions.
  26. Vector3 localWhichPosition;
  27.  
  28. // Luigi is in the middle.
  29. localWhichPosition = Vector3.zero;
  30.  
  31. // Left, Down, Right, Up
  32. if (Input.GetKey(KeyCode.LeftArrow))
  33. {
  34. localWhichPosition = 2 * Vector3.left;
  35.  
  36. }
  37. else
  38. if (Input.GetKey(KeyCode.RightArrow))
  39. {
  40. localWhichPosition = 2 * Vector3.right;
  41. }
  42.  
  43. if (Input.GetKey(KeyCode.UpArrow))
  44. {
  45. localWhichPosition = 2 * Vector3.up;
  46.  
  47. }
  48. else
  49. if (Input.GetKey(KeyCode.DownArrow))
  50. {
  51. localWhichPosition = 2 * Vector3.down;
  52. }
  53.  
  54. // Left & Up
  55. if (Input.GetKey(KeyCode.LeftArrow && UpArrow))
  56. {
  57. localWhichPosition = 2 * Vector3.left;
  58. localWhichPosition = 2 * Vector3.up;
  59.  
  60. }
  61. else
  62. if (Input.GetKey(KeyCode.RightArrow && DownArrow))
  63. {
  64. localWhichPosition = 2 * Vector3.right;
  65. localWhichPosition = 2 * Vector3.down;
  66. }
  67.  
  68. // Right & Up
  69. if (Input.GetKey(KeyCode.RightArrow && UpArrow))
  70. {
  71. localWhichPosition = 2 * Vector3.right;
  72. localWhichPosition = 2 * Vector3.up;
  73.  
  74. }
  75. else
  76. if (Input.GetKey(KeyCode.LeftArrow && DownArrow))
  77. {
  78. localWhichPosition = 2 * Vector3.left;
  79. localWhichPosition = 2 * Vector3.down;
  80. }
  81.  
  82. // Left & Down
  83. if (Input.GetKey(KeyCode.LeftArrow && DownArrow))
  84. {
  85. localWhichPosition = 2 * Vector3.left;
  86. localWhichPosition = 2 * Vector3.down;
  87.  
  88. }
  89. else
  90. if (Input.GetKey(KeyCode.RightArrow && DownArrow))
  91. {
  92. localWhichPosition = 2 * Vector3.right;
  93. localWhichPosition = 2 * Vector3.up;
  94. }
  95.  
  96. // Right & Down
  97. if (Input.GetKey(KeyCode.RightArrow && DownArrow))
  98. {
  99. localWhichPosition = 2 * Vector3.right;
  100. localWhichPosition = 2 * Vector3.down;
  101.  
  102. }
  103. else
  104. if (Input.GetKey(KeyCode.RightArrow && DownArrow))
  105. {
  106. localWhichPosition = 2 * Vector3.left;
  107. localWhichPosition = 2 * Vector3.up;
  108. }
  109.  
  110. // You have to set the transform position
  111. // to actually change Luigi's position.
  112.  
  113. this.transform.position = localWhichPosition;
  114.  
  115. if (Input.GetKeyDown(KeyCode.Space))
  116. {
  117. // Change the sprite to the blue color.
  118. memberSpriteRenderer.color = memberBlueColor;
  119. }
  120. else
  121. if (Input.GetKeyUp(KeyCode.Space))
  122. {
  123. // Change the sprite to the normal color.
  124. memberSpriteRenderer.color = memberNormalColor;
  125.  
  126. /******** START NEW CODE ********/
  127. // Kill the ghost.
  128. this.gameObject.SetActive(false);
  129. /********* END NEW CODE *********/
  130.  
  131. // Create a color variable.
  132.  
  133. Color localColor;
  134. localColor = Color.black;
  135.  
  136. // You can get the sprite color (you don't have to, but you can).
  137.  
  138. localColor = memberSpriteRenderer.color;
  139.  
  140. // Change a color.
  141.  
  142. localColor.r = 1.0f; // 0.0 is no red, 1.0 is max red.
  143. localColor.g = 0.5f; // 0.0 is no green, 1.0 is max green.
  144. localColor.b = 0.0f; // 0.0 is no blue, 1.0 is max blue.
  145. localColor.a = 0.5f; // 0.0 is completely invisible, 1.0f is completely visible.
  146.  
  147. // You have to change the sprite renderer color
  148. // to actually change the color.
  149.  
  150. memberSpriteRenderer.color = localColor;
  151.  
  152. }
  153. }
  154.  
  155.  
  156.  
  157.  
Advertisement
Add Comment
Please, Sign In to add comment