Home
mid.png

2017.11.10. Term Project Mid Demo


            

데모 영상

Script

using System.Collections; using System.Collections.Generic; using UnityEngine; public class PrisonerController : MonoBehaviour { Animator animator; Rigidbody2D rigidBody; public GameObject label; void Start(){ animator = GetComponent[Animator](); rigidBody = GetComponent[Rigidbody2D](); label = GameObject.Find("Label"); } void ButtonPush(string buttonName){ if(buttonName == "Work") { animator.SetBool("MovingRight", true); rigidBody.velocity = new Vector2 (4, 0); } else { animator.SetBool("MovingLeft", true); rigidBody.velocity = new Vector2 (-4, 0); } Invoke("FinishMove", 2.5f); } void FinishMove(){ animator.SetBool("MovingLeft", false); animator.SetBool("MovingRight", false); rigidBody.velocity = new Vector2 (0, 0); transform.position = new Vector3 (0, 0, 0); label.SendMessage("FinishMove", SendMessageOptions.DontRequireReceiver); } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class ButtonPush : MonoBehaviour { public Animator lineAnimator; public GameObject label; public GameObject prisoner; public float t1; public int myId; GameObject showerButtonObject; GameObject workButtonObject; public bool isWorkButton; void Start(){ lineAnimator = GameObject.Find("Line").GetComponent[Animator](); label = GameObject.Find("Label"); prisoner = GameObject.Find("Prisoner"); myId = gameObject.GetInstanceID(); //자기확인 if(GameObject.Find("Workbutton").GetInstanceID() == myId) { isWorkButton = true; showerButtonObject = GameObject.Find("Showerbutton"); } else { isWorkButton = false; workButtonObject = GameObject.Find("Workbutton"); } } void OnMouseDown() { Debug.Log("눌렀따!"); if(isWorkButton) { Debug.Log("일"); if (Time.time - t1 > 4) //4초 마다 버튼 누르기 가능 { //시간 기록 t1 = Time.time; //오브젝트로 ButtonPush 함수 실행 명령 뿌리기. lineAnimator.SetTrigger("ButtonPush"); label.SendMessage("ButtonPush", "Work"); prisoner.SendMessage("ButtonPush", "Work"); } } else { Debug.Log("샤워"); t1 = workButtonObject.GetComponent[ButtonPush]().t1; if(Time.time - t1 > 4){ //시간은 WorkButton 오브젝트를 중심으로 한다. 시간 기록. workButtonObject.GetComponent[ButtonPush]().t1 = Time.time; //오브젝트로 ButtonPush 함수 실행 명령 뿌리기. lineAnimator.SetTrigger("ButtonPush"); label.SendMessage("ButtonPush", "Shower"); prisoner.SendMessage("ButtonPush", "Shower"); } } } void OnMouseUp() { } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class LabelController : MonoBehaviour{ public SpriteRenderer spriteRenderer; public Sprite labelBlueTriangle; public Sprite labelYellowStar; public Sprite labelVioletSquare; int spriteChosing; void Start(){ spriteRenderer = GetComponent[SpriteRenderer](); Labeling(); } void ButtonPush(string buttonName){ //라벨 판별 //라벨 바꾸기 Labeling(); //라벨 숨기기 spriteRenderer.sortingLayerName = "Defalut"; } public void Labeling() { spriteChosing = Random.Range(1, 3); if(spriteChosing == 1) { spriteRenderer.sprite = labelBlueTriangle; } else if(spriteChosing == 2) { spriteRenderer.sprite = labelYellowStar; } else if(spriteChosing == 3) { spriteRenderer.sprite = labelVioletSquare; } } void FinishMove(){ spriteRenderer.sortingLayerName = "Prisoner"; } }