프로젝트 하나 만듬

Sphere랑 Plane을 하나씩 생성

GameObject 생성

GameObject의 이름을 TimerManager로 바꿈

Add Component 에서 TimerManager.cs를 생성

더블 클릭하여 TimeManager 스크립트를 실행

하기전에 GameObject하나 더 생성

GameObject를 RespawnPosition으로 이름을 바꿈

 Plane 위쪽으로 Position 값을 준다. 

 

Sphere 오브젝트를 프리펩스로 만듬.

바닥으로 떨어트리기 위해 Rigidbody 컴포넌트를 달아주고 Drag 값을 0.5로 바꿈 (공기 저항 값을 줘 살살 내려오게)

코루틴도 멈추는지 테스트 하기 위해 UGUI Text 생성

 

TimeManager.cs의 스크립트를 집어넣음

TimeManager.cs의 코드

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimeManager : MonoBehaviour
{
    public GameObject respawnPosotion;
    public GameObject sphereObj;

    public float slowdownFactor = 0.05f;
    public float slowdownLength = 2f;

    public Text countText;

    public void DoSlowMotion()
    {
        Time.timeScale = slowdownFactor;
        Time.fixedDeltaTime = Time.timeScale * .02f;
    }

    // Use this for initialization
    void Start()
    {
        StartCoroutine(ITimer());
    }

    private void KeyController()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            DoSlowMotion();
        }
        if (Input.GetButtonDown("Fire2"))
        {
            Time.timeScale = 1f;
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(sphereObj, respawnPosotion.transform.position, respawnPosotion.transform.rotation);
        }
    }

    // Update is called once per frame
    void Update()
    {

        KeyController();

        // 점점 빨라짐
        //Time.timeScale += (1f / slowdownLength) * Time.unscaledDeltaTime;
        //Time.timeScale = Mathf.Clamp(Time.timeScale, 0f, 1f);
    }

    IEnumerator ITimer()
    {
        int i = 0;
        while (true)
        {
            countText.text = i.ToString();
            yield return new WaitForSeconds(0.1f);
            i++;
        }
    }
}

 

드래그해서 넣어주고 Factor, Length 값을 설정함.

 

실행

 

스페이스바를 누르면 공 생성. 마우스 왼쪽 버튼을 눌러 슬로우모션으로 만듬. 마우스 오른쪽 버튼을 눌러 슬로우 모션을 품.

위의 주석을 해제하면 자연스럽게 슬로우 모션이 풀림.

 

사운드도 슬로우 되는지 Audio source를 넣어봐서 실험해봤는데 사운드는 슬로우가 안됨.

슬로우를 하려면 Pitch 값을 조절해주는 코드를 만들어서 사용해야 됨.

 

 

 

참고 동영상

https://www.youtube.com/watch?v=0VGosgaoTsw&t=604s

https://docs.unity3d.com/kr/2018.1/Manual/ScriptingRuntimeUpgrade.html

 

스크립팅 런타임 업그레이드 - Unity 매뉴얼

2017.1 버전의 경우, 프로젝트 옵션에 따라 .NET 4.6을 실험적으로 사용할 수 있습니다. 이 옵션은 Scripting Backend 또는 Api Compatibility Level 위 플레이어 설정에 GUI로 위치하고 있습니다.

docs.unity3d.com

 

Edit -> Project Settings -> Player

Configuration -> Scripting Runtime Version

내 OS는 윈도우 10임

 

구글에 nodejs 입력.

nodejs 사이트 들어간다.

LTS 버리고 현재버전으로 가즈아~ 다운로드(https://nodejs.org/ko/)

nodejs

설치 시작

기다리면 next 버튼을 누를 수 있다

설정 해 줄 사람은 해주라우~ 나는 안한다우

 

설치완료

 

vscode를 킵시다. 없으면 다운로드 받으셩 (https://code.visualstudio.com/)

 

폴더 만들고

 

js 파일도 하나 만들어서 스크립트를 작성하고

터미널 연다음 입력해보면

잘 나오넵

혹시 에러 생기면 경로가 제대로 맞는지 확인하라굿~

+ Recent posts