Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Luigi Script
- //name
- using UnityEngine;
- class LuigiScript : MonoBehaviour
- {
- [SerializeField] private Color memberNormalColor = Color.green;
- [SerializeField] private Color memberBlueColor = Color.blue;
- private SpriteRenderer memberSpriteRenderer = null;
- }
- // Update is called once per frame
- void Update()
- {
- // Get the sprite renderer.
- memberSpriteRenderer = GetComponent<SpriteRenderer>();
- // Vectors are variables that mean positions.
- Vector3 localWhichPosition;
- // Luigi is in the middle.
- localWhichPosition = Vector3.zero;
- // Left, Down, Right, Up
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- localWhichPosition = 2 * Vector3.left;
- }
- else
- if (Input.GetKey(KeyCode.RightArrow))
- {
- localWhichPosition = 2 * Vector3.right;
- }
- if (Input.GetKey(KeyCode.UpArrow))
- {
- localWhichPosition = 2 * Vector3.up;
- }
- else
- if (Input.GetKey(KeyCode.DownArrow))
- {
- localWhichPosition = 2 * Vector3.down;
- }
- // Left & Up
- if (Input.GetKey(KeyCode.LeftArrow && UpArrow))
- {
- localWhichPosition = 2 * Vector3.left;
- localWhichPosition = 2 * Vector3.up;
- }
- else
- if (Input.GetKey(KeyCode.RightArrow && DownArrow))
- {
- localWhichPosition = 2 * Vector3.right;
- localWhichPosition = 2 * Vector3.down;
- }
- // Right & Up
- if (Input.GetKey(KeyCode.RightArrow && UpArrow))
- {
- localWhichPosition = 2 * Vector3.right;
- localWhichPosition = 2 * Vector3.up;
- }
- else
- if (Input.GetKey(KeyCode.LeftArrow && DownArrow))
- {
- localWhichPosition = 2 * Vector3.left;
- localWhichPosition = 2 * Vector3.down;
- }
- // Left & Down
- if (Input.GetKey(KeyCode.LeftArrow && DownArrow))
- {
- localWhichPosition = 2 * Vector3.left;
- localWhichPosition = 2 * Vector3.down;
- }
- else
- if (Input.GetKey(KeyCode.RightArrow && DownArrow))
- {
- localWhichPosition = 2 * Vector3.right;
- localWhichPosition = 2 * Vector3.up;
- }
- // Right & Down
- if (Input.GetKey(KeyCode.RightArrow && DownArrow))
- {
- localWhichPosition = 2 * Vector3.right;
- localWhichPosition = 2 * Vector3.down;
- }
- else
- if (Input.GetKey(KeyCode.RightArrow && DownArrow))
- {
- localWhichPosition = 2 * Vector3.left;
- localWhichPosition = 2 * Vector3.up;
- }
- // You have to set the transform position
- // to actually change Luigi's position.
- this.transform.position = localWhichPosition;
- if (Input.GetKeyDown(KeyCode.Space))
- {
- // Change the sprite to the blue color.
- memberSpriteRenderer.color = memberBlueColor;
- }
- else
- if (Input.GetKeyUp(KeyCode.Space))
- {
- // Change the sprite to the normal color.
- memberSpriteRenderer.color = memberNormalColor;
- /******** START NEW CODE ********/
- // Kill the ghost.
- this.gameObject.SetActive(false);
- /********* END NEW CODE *********/
- // Create a color variable.
- Color localColor;
- localColor = Color.black;
- // You can get the sprite color (you don't have to, but you can).
- localColor = memberSpriteRenderer.color;
- // Change a color.
- localColor.r = 1.0f; // 0.0 is no red, 1.0 is max red.
- localColor.g = 0.5f; // 0.0 is no green, 1.0 is max green.
- localColor.b = 0.0f; // 0.0 is no blue, 1.0 is max blue.
- localColor.a = 0.5f; // 0.0 is completely invisible, 1.0f is completely visible.
- // You have to change the sprite renderer color
- // to actually change the color.
- memberSpriteRenderer.color = localColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment