Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hero Script - Adventure
- // name
- using UnityEngine;
- public class HeroScript : MonoBehaviour
- {
- // Set my Speed. If There is no speed, you can't move.
- [SerializeField] private float memberSpeed = 3.0f;
- // I still don't know. I'm assuming it calls the Sprite Renderer, but I don't know what null is.
- private SpriteRenderer memberSpriteRenderer = null;
- // I STILL don't know. Rigid Body.
- private Rigidbody2D memberRigidBody = null; // I don't know, I'll tell you later.
- // Green Key
- private bool memberHasGreenKey = false;
- // Orange Key
- private bool memberHasOrangeKey = false;
- // Master Key
- private bool memberHasMasterKey = false;
- // Score
- private int memberScore = 0;
- // Lance
- private bool memberHasLance = false;
- // Sword
- private bool memberHasSword = false;
- // Start is called before the first frame update
- void Start()
- {
- // Get the rigid body that we added in Unity.
- memberRigidBody = this.GetComponent<Rigidbody2D>();
- }
- // Update is called once per frame
- void Update()
- {
- // Which direction does the player want to go?
- // Assume the player doesn't want to move, so no direction.
- Vector3 localWhichDirection;
- localWhichDirection = Vector3.one;
- // Get movement input
- float horizontalInput = Input.GetAxis("Horizontal");
- float verticalInput = Input.GetAxis("Vertical");
- // Calculate movement direction
- Vector3 movementDirection = new Vector3(horizontalInput, verticalInput);
- // Apply movement
- memberRigidBody.velocity = movementDirection * memberSpeed;
- // Hero just collided with something.
- void OnCollisionEnter2D(Collision2D localCollision)
- {
- // What is the other object?
- GameObject localOtherObject = localCollision.gameObject;
- {
- // Is it a Green Key?
- if (localOtherObject.name.StartsWith("Green Key"))
- {
- // Gain Green Key.
- memberHasGreenKey = true;
- }
- // Is it a Coin?
- if (localOtherObject.name.StartsWith("Coin"))
- {
- // Increase the score.
- memberScore++;
- print(memberScore);
- }
- // Is it an Orange Key?
- if (localOtherObject.name.StartsWith("Orange Key"))
- {
- // Gain Orange Key
- memberHasOrangeKey = true;
- }
- // Is it a Sword?
- if (localOtherObject.name.StartsWith("Sword"))
- {
- memberHasSword = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement