PlayerController
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
private enum eAnimState
{
Idle, RunF
}
[SerializeField]
private CJoystick joystick; //조이스틱 가져오기
[SerializeField]
private GameObject portalGo;
[SerializeField]
private DoorController leftDoorController;
[SerializeField]
private DoorController RightDoorController;
[SerializeField]
private FadeOutMain fadeOutMain;
[SerializeField]
private Text text;
[SerializeField]
private float radius = 10f;
private Animator anim;
void Start()
{
this.anim = this.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
//Ray로 한번 발견이나 해보자
Ray ray = new Ray(this.transform.position, this.transform.forward);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 1000f))
{
DrawArrow.ForDebug(this.transform.position, hit.collider.transform.position, 2f, Color.red, ArrowType.Solid);
if (hit.collider.tag == "Monster")
{
Debug.Log("몬스터");
}
}
//조이스틱을 마우스로 누르면 플레이어가 그 방향으로 움직인다.
float h = this.joystick.Horizontal;
float v = this.joystick.Vertical;
Vector3 moveDir = new Vector3(h, 0, v);
//애니메이션 구현
if (moveDir == Vector3.zero)
{
this.PlayAnimation(eAnimState.Idle);
}
else
{
float angle = Mathf.Atan2(moveDir.x, moveDir.z) * Mathf.Rad2Deg;
Quaternion angleRotation = Quaternion.AngleAxis(angle, Vector3.up);
this.transform.rotation = angleRotation;
this.PlayAnimation(eAnimState.RunF);
this.transform.Translate(Vector3.forward * 5f * Time.deltaTime);
}
}
private void PlayAnimation(eAnimState state)
{
this.anim.SetInteger("State", (int)state);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "Door")
{
fadeOutMain.FadeOutAndSceneManager();
}
else if (collision.collider.tag == "Portal")
{
Destroy(this.portalGo);
leftDoorController.OpenDoor();
RightDoorController.OpenDoor();
this.text.text = "좋습니다. 문을 통해 \n계속 이동하세요.";
}
}
}
Stage1SceneMain
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Stage1SceneMain : MonoBehaviour
{
[SerializeField]
private Image dim;
private void Start()
{
this.StartCoroutine(this.CoFadeInAndSceneManager());
}
private IEnumerator CoFadeInAndSceneManager()
{
Color color = this.dim.color;
while (true)
{
color.a -= 0.01f;
this.dim.color = color;
if(color.a <= 0)
{
break;
}
yield return null;
}
}
}
'유니티 심화' 카테고리의 다른 글
HeroShooter - 가까운 거리 몬스터 선 그리기 (0) | 2023.08.24 |
---|---|
절대강좌 유니티 - 혈흔효과, 몬스터 공격효과, 델리게이트, 죽으면 강남스타일, 본 구조, 충돌감지, 몬스터 사망 (0) | 2023.08.24 |
절대강좌 유니티 - 애니메이션, 몬스터 [피격, 공격, 추적, 정지] (0) | 2023.08.23 |
절대강좌 유니티 - NavMeshSurface (0) | 2023.08.23 |
절대강좌 유니티 - MuzzleFlash (0) | 2023.08.22 |