Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections; //Unity
- using System.Collections.Generic; //Unity
- using UnityEngine; //UnityEngine namespace
- public class Player : MonoBehaviour //Public script player
- {
- [SerializeField] Sprite scissor; //Create asset-drop field called "scissor" to assign the scissor sprite
- [SerializeField] Sprite rock; //Create asset-drop field called "rock" to assign the rock sprite
- [SerializeField] Sprite paper; //Create asset-drop field called "paper" to assign the paper sprite
- int PlayerValue; //Create integer that will receive player value from script "Player"
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.LeftArrow)) //If the left arrow is pressed
- {
- GetComponent<SpriteRenderer>().sprite = rock; //Get the actor component "Sprite Renderer" and change the sprite to the "rock" sprite
- PlayerValue = 1;
- }
- else if (Input.GetKeyDown(KeyCode.DownArrow)) //If the down arrow is pressed
- {
- GetComponent<SpriteRenderer>().sprite = scissor; //Get the actor component "Sprite Renderer" and change the sprite to the "scissor" sprite
- PlayerValue = 2;
- }
- else if (Input.GetKeyDown(KeyCode.RightArrow)) //If the right arrow is pressed
- {
- GetComponent<SpriteRenderer>().sprite = paper; //Get the actor component "Sprite Renderer" and change the sprite to the "scissor" sprite
- PlayerValue = 0;
- }
- }
- public int ReadPlayerValue()
- {
- return PlayerValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement