moonee-e3 님의 블로그
2024-05-31 | 3D에서 2D 스프라이트 화면에 맞게 나타내기 본문
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class StartStoryPlay : MonoBehaviour
{
//참고 링크 : https://youtu.be/icYDYFFBVCc?si=x6FVV7yZNFtz5KgR
private void Awake() // 카메라에 오브젝트 크기 맞추기
{
float spritex = SR.sprite.bounds.size.x;
float spritey = SR.sprite.bounds.size.y;
float screenY = Camera.main.orthographicSize * 2;
float screenX = screenY / Screen.height * Screen.width;
transform.localScale = new Vector3(Mathf.Ceil(screenX / spritex), Mathf.Ceil(screenY / spritey));
}
public SpriteRenderer SR;
public Sprite[] IntroScene; // 씬 넣을 배열
int index = 0;
public Sprite Intro3;
public Sprite Intro6;
private void Start()
{
index = 0;
SR = GetComponent<SpriteRenderer>();
}
private void Update()
{
SceneStart();
}
void SceneStart()
{
if (Input.GetKeyDown(KeyCode.Space))
{
index++; // index가 점점 늘어남
//Debug.Log(IntroScene.Length + "///////////" + index);
SR.sprite = IntroScene[index]; //image의 sprite를 불러와서 index 순으로 함
if (index == 1 || index == 3)
{
StartCoroutine(AnimaIntro());
}
if (IntroScene.Length <= index + 1) //sprite의 길이가 index의 수만큼
{
SceneManager.LoadScene("StartCinema");
}
}
}
IEnumerator AnimaIntro()
{
while (index == 1)
{
SR.sprite = IntroScene[1];
yield return new WaitForSeconds(1f);
if(index == 1) // 한 번더 확인 해줌으로써 코드가 꼬이지 않게 함
{
SR.sprite = Intro3;
yield return new WaitForSeconds(1f);
}
else
{
break;
}
}
while (index == 3)
{
SR.sprite = IntroScene[3];
yield return new WaitForSeconds(1f);
if (index == 3)
{
SR.sprite = Intro6;
yield return new WaitForSeconds(1f);
}
else
{
break;
}
}
yield return null;
}
}
'개발 일지 [3D | Dream Forest]' 카테고리의 다른 글
204-06-14 | 움직이는 땅 (0) | 2024.06.23 |
---|---|
2024-06-14 | 포탈_닿으면 플레이어 위치 이동 (0) | 2024.06.22 |
2024-05-25 같은 위치 반복해서 움직이는 적 (0) | 2024.06.22 |
2024-05-28 시야각에 들어오면 죽이는 적 구현 (0) | 2024.06.21 |
2024-05-20 플레이어의 카메라 시점 변경 (0) | 2024.06.21 |