HeroShoot-1. 튜토리얼 씬(캐릭터 이동/회전, 특정 위치 도달시 포탈 오픈)
조이스틱으로 캐릭터 움직이기
=> transform.Translate 사용.
지정된 위치까지 이동하면 포탈열림/ 다음스테이지로 이동
=>OnCollisonEnter를 사용했다. 포탈과 문에 각각 collider를 달아주고, CompareTag를 통해 태그를 구별한다.
https://docs.unity3d.com/ScriptReference/Component.CompareTag.html
캔버스에 이미지 넣어서 안내하는 캐릭터 만들기
setNativeSize를 누르면 원사이즈로 들어간다.
-Play하자마자 비활성화되어 있던 두 이미지 객체를 활성화한다.
-speech_bubble 오브젝트의 자식인 Text의 컴포넌트를 불러오기 위해 GetComponentInChildren을 사용.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
[SerializeField] private VariableJoystick joystick;
[SerializeField] private float moveSpeed = 3f;
[SerializeField] private TutorialMain tutorialMain;
private Vector3 downPosition;
private bool isDown = false;
private Animator anim;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float h = this.joystick.Direction.x;
float v = this.joystick.Direction.y;
Vector3 moveDir = (Vector3.forward * v) + Vector3.right * h;
float angle = Mathf.Atan2(moveDir.x, moveDir.z) * Mathf.Rad2Deg;
//조이스틱으로 입력받아 방향 바라보게함
if (moveDir != Vector3.zero)
{//이동
this.transform.Translate(moveDir.normalized * this.moveSpeed * Time.deltaTime,Space.World);
this.transform.localRotation = Quaternion.AngleAxis(angle, Vector3.up);//축으로 회전
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag("Portal"))
{
Debug.Log("Portal");
Destroy(collision.gameObject);
this.tutorialMain.OpenGate();
}
else if (collision.collider.CompareTag("Stage1"))
{
Debug.Log("Stage1");
SceneManager.LoadScene("Stage1");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TutorialMain : MonoBehaviour
{
[SerializeField] private GameObject gateLeftGo;
[SerializeField] private GameObject gateRightGo;
[SerializeField] private GameObject npcGo;
[SerializeField] private GameObject speechGo;
private Text text;
// Start is called before the first frame update
void Start()
{
//시작시 안내 UI Active.
this.npcGo.SetActive(true);
this.speechGo.SetActive(true);
this.text = this.speechGo.GetComponentInChildren<Text>();
this.text.text = "목표 지점까지 이동하세요!";
}
// Update is called once per frame
void Update()
{
}
public void OpenGate()
{
Debug.Log("OpenGate");
this.gateLeftGo.transform.Rotate(0,90,0);
this.gateRightGo.transform.Rotate(0,-90, 0);
this.text.text = "잘했어요! 문이 열렸으니 이동해볼까요?";
}
}
'3d 콘텐츠 제작' 카테고리의 다른 글
HeroShoot- Stage1, 씬 로드 변경 (0) | 2023.08.24 |
---|---|
HeroShoot-튜토리얼 씬 수정(조이스틱, fadeOut,Gate에 Slerp) (0) | 2023.08.23 |
HeroShoot-구현 내용/ 씬 구성 (0) | 2023.08.22 |
SimpleRPG- Boss Scene(수정중) (0) | 2023.08.13 |
SimpleRPG - GameScene에서 몬스터 사망시 아이템 획득 후 장착 > 포탈타고 이동 구현+fade in, out>씬전환 (0) | 2023.08.13 |