씬 로드및 최종 점수처리를 간단히 해보고 길고 길었던 스터디를 마무리 합니다.
//카메라 -----------------------
using UnityEngine;
using System.Collections;
public class Cam : MonoBehaviour {
public Transform Target;
public Transform Camera;
private Vector3 CamPos;
public float CamX;
public float CamY;
public float CamSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
CamPos = new Vector3 (Target.position.x + CamX , CamY, Target.transform.position.z);
Camera.transform.position = Vector3.Lerp (Camera.transform.position, CamPos, Time.smoothDeltaTime * CamSpeed);
}
}
//캐릭터 -----------------------
using UnityEngine;
using System.Collections;
public class CharMove : MonoBehaviour {
//public
public GameObject Target;
public float MovePower = 0.5f;
public float MoveSpeed = 5.0f;
public float RotationSpeed = 20.0f;
public float ReturnPower = 0.5f;
//private
private float TargetPosition;
private float TargetSetPosition;
private Quaternion RotationQ;
private bool OnForward;
private bool OnLeft;
private bool OnRight;
private bool OnBack;
private bool Moving;
private bool StateForward;
private bool StateLeft;
private bool StateRight;
private bool StateBack;
//Collider Controller
private string OnMoveVecter = "State";
private string StayVecter = "State";
//UI
public GameObject ScoreLabel;
private int num = 1;
// Use this for initialization
void Start () {
ScoreLabel = GameObject.Find ("ScoreLabel");
}
// Update is called once per frame
void Update () {
//Debug.Log ("OnMoveVecter : "+OnMoveVecter);
//forward move
if(OnForward){
Moving = true;
Target.gameObject.transform.position += new Vector3(MovePower,0,0)*(Time.deltaTime * MoveSpeed);
TargetPosition = Target.gameObject.transform.position.x;
//Rotation
RotationQ = Quaternion.Euler(0,0,0);
Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, RotationQ , RotationSpeed * Time.deltaTime);
if(TargetPosition >= TargetSetPosition){
OnForward = false;
Moving = false;
}
}
// Left move
if(OnLeft){
Moving = true;
Target.gameObject.transform.position += new Vector3(0,0,MovePower)*(Time.deltaTime * MoveSpeed);
TargetPosition = Target.gameObject.transform.position.z;
//Rotation
RotationQ = Quaternion.Euler(0,-90.0f,0);
Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, RotationQ , RotationSpeed * Time.deltaTime);
if(TargetPosition >= TargetSetPosition){
OnLeft = false;
Moving = false;
}
Moving = false;
}
// Right move
if(OnRight){
Moving = true;
Target.gameObject.transform.position -= new Vector3(0,0,MovePower)*(Time.deltaTime * MoveSpeed);
TargetPosition = Target.gameObject.transform.position.z;
//Rotation
RotationQ = Quaternion.Euler(0,90.0f,0);
Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, RotationQ , RotationSpeed * Time.deltaTime);
if(TargetPosition <= TargetSetPosition){
OnRight = false;
Moving = false;
}
}
// Back move
if(OnBack){
Moving = true;
Target.gameObject.transform.position -= new Vector3(MovePower,0,0)*(Time.deltaTime * MoveSpeed);
TargetPosition = Target.gameObject.transform.position.x;
//Rotation
RotationQ = Quaternion.Euler(0,180.0f,0);
Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, RotationQ , RotationSpeed * Time.deltaTime);
if(TargetPosition <= TargetSetPosition){
OnBack = false;
Moving = false;
}
}
}
//forward move btn
public void CharForwardMove(){
if (Moving == false & StateForward == false) {
TargetSetPosition = Target.gameObject.transform.position.x + MovePower;
OnForward = true;
OnMoveVecter = "ForwardVecter";
num = num + 1;
ScoreLabel.GetComponent<UILabel>().text = num.ToString();
}
}
// Left move btn
public void CharLeftMove(){
if(Moving == false & StateLeft == false){
TargetSetPosition = Target.gameObject.transform.position.z + MovePower;
OnLeft = true;
OnMoveVecter = "LetfVecter";
}
}
// Right move btn
public void CharRightMove(){
if (Moving == false & StateRight == false) {
TargetSetPosition = Target.gameObject.transform.position.z - MovePower;
OnRight = true;
OnMoveVecter = "RightVecter";
}
}
//forward move btn
public void CharBackMove(){
if (Moving == false & StateBack == false) {
TargetSetPosition = Target.gameObject.transform.position.x - MovePower;
OnBack = true;
OnMoveVecter = "BackVecter";
num = num - 1;
ScoreLabel.GetComponent<UILabel>().text = num.ToString();
}
}
//Trigger ON
void OnTriggerEnter(Collider col){
StayVecter = OnMoveVecter;
}
//collider
void OnTriggerStay(Collider col){
//Debug.Log ("TriggerStay : " + "Trigger Stay!!");
if(StayVecter == "ForwardVecter"){
StateForward = true;
}else if(StayVecter == "LetfVecter"){
StateLeft = true;
}else if(StayVecter == "RightVecter"){
StateRight = true;
}else if(StayVecter == "BackVecter"){
StateBack = true;
}
}
void OnTriggerExit(Collider col){
StateForward = false;
StateLeft = false;
StateRight = false;
StateBack = false;
OnMoveVecter = "State";
StayVecter = "State";
}
/* collider Test
void OnCollisionEnter(Collision col){
Debug.Log ("OnCollisionEnter");
}
void OnCollisionExit(Collision col){
Debug.Log ("OnCollisionExit");
}
void OnCollisionStay(Collision col){
Debug.Log ("OnCollisionStay");
}
void OnTriggerEnter(Collider col){
Debug.Log ("OnTriggerEnter");
}
void OnTriggerExit(Collider col){
Debug.Log ("OnTriggerExit");
}
void OnTriggerStay(Collider col){
Debug.Log ("OnTriggerStay");
}
*/
}
//게임오버 UI -----------------------
using UnityEngine;
using System.Collections;
public class GameOverColl : MonoBehaviour {
public GameObject GameOverLabal;
// Use this for initialization
void Start () {
GameOverLabal = GameObject.Find ("GameOver_UI");
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider col){
if(col.gameObject.tag == "Player"){
GameOverLabal.GetComponent<UIPanel> ().alpha = 1;
}
}
}
'Unity공부 > Unity C# 사내 스터디' 카테고리의 다른 글
Unity c# for designer - 7강 (점수, 장애물) (0) | 2017.03.13 |
---|---|
Unity c# for designer - 6강(회전,충돌) (0) | 2017.01.23 |
Unity c# for designer - 5강 보충 수업 (0) | 2016.12.02 |
Unity c# for designer - 5강 (미니게임 만들며 Script 배우기) (0) | 2016.11.28 |
Unity c# for designer 4강 / 클래스 (0) | 2016.11.28 |