반응형

출처:  https://rupicat.com/entry/Signing-for-Unity-iPhone-requires-a-development-team-에러-문제 [Rupicat's Tech Reviews:티스토리]

 

Signing for "Unity-iPhone" requires a development team. 에러 문제

Xcode에서 사이닝을 설정 했는데

Signing for "Unity-iPhone" requires a development team.

이라는 에러가 발생한다면,

 

Xcode Signing & Capabilities 에서 All 탭을 누르고 Personal Team을 선택.

최초에  Debug 선택되어 있어 있음.

 

 

반응형
반응형

출처: https://penguinofdev.tistory.com/51

특정 조건에 맞는 LIst 안의 원소를 제거할 때, 별 생각없이 이렇게 할 때가 있다.

for(int i = 0; i < myList.Count; i++)
{
	if(조건이 참일 때)
		myList.Remove(myList[i]);
}

배열이 됐든 무엇이든 순회하는 과정에서 컨테이너의 내용이 변경되는 것은 위험한 작업일 수 있다.

 

위 코드도 중간에 어떤 값이 제거되면, list의 사이즈 역시 변경되어 잘못된 인덱스에 접근할 가능성이 매우 높다.

 

이럴 때는 다음과 같이 사용하자.

for(int i = myList.Count - 1; i >= 0; i--)
{
	if(조건이 참이면)
    		myList.Remove(myList[i]);
}

거꾸로 순회하면서 제거하면 안전하게 작업을 수행할 수 있다.

 

 

 

- Question

InvalidOperationException: The list was modified.

InvalidOperationException: The list was modified. Boo.Lang.List`1+c__Iterator6[UnityEngine.GameObject].MoveNext () Item.OnCollisionExit (UnityEngine.Collision collision) (at Assets/Item.js:73)

I simply want a list with item I currently collide with, so when I stop colliding they must be removed from the list:

EDIT: I changed my code but now it gives an index out of range exception

  1. function OnCollisionExit(collision : Collision) {
  2. for(var i = tegenstanders.Count; i> 0; i--)
  3. {
  4. item = tegenstanders[i];
  5. if(item.name == collision.gameObject.name)
  6. {
  7. tegenstanders.Remove(tegenstanders[i]);
  8. }
  9. }
  10. }

- Answer


This happens because you're removing items from the list at the same time as you are iterating through it. It's easier to explain if you convert the list to a non-enumerated for-loop instead:

  1. List<int> example = new List<int>();
  2. for (int i = 0; i < example.Count; i++)
  3. {
  4. if (something)
  5. example.Remove(example[i]); // Not safe to do
  6.  
  7. }

If you remove an item from the list while you're going through it, the for-loop's impression of the list's Count-property is no longer reliable, since the amount of elements in the list changed during execution of the loop. In addition, the enumeration is now messed up; example[i] now points to another item in the list, because the Remove-command has shifted all of the elements with a higher index down to keep them sequential in memory, so you would effectively skip an item if you kept iterating with it. That's why the enumerated version of the loop doesn't enjoy it very much when you modify the List in it.

To get around this issue, use a standard for-loop and iterate through the list backwards instead:

  1. List<int> example = new List<int>();
  2. for (int i = example.Count-1; i >= 0; i--)
  3. {
  4. if (something)
  5. example.Remove(example[i]); // Safe to do
  6. }

This is not a problem, because you're stopping iteration at 0, not at List.Count, and all of your indexes still point to the right elements just fine, because the elements get shifted down on Remove, and you've already iterated through those.

반응형
반응형

출처: https://velog.io/@kwt0124/%EC%9C%A0%EB%8B%88%ED%8B%B0-%ED%94%84%EB%A6%AC%ED%8C%B9-Load%ED%95%98%EB%8A%94-3%EA%B0%80%EC%A7%80-%EB%B0%A9%EB%B2%95

  //1. Load 사용하는 방법 
        bullet = (GameObject)Resources.Load("Prefabs/Bullet");
        //2. 형변환해서 Load 하는 방법 - 캐스팅에 성공하면 결과를 리턴하고.
        //실패하면 null값을 리턴한다. -> 구글링참고
        bullet = Resources.Load("Prefabs/Bullet") as GameObject;
        //3. 일반적인 Load 하는 방법.
        bullet = Resources.Load<GameObject>("Prefabs/Bullet");

 

유니티에서 Resources.Load 함수를 사용하여 에셋 로드하기

Resource 폴더는 유니티가 특별한 목적으로 예약한 폴더 중 하나로 해당 폴더에 에셋을 위치시키면 load함수를 사용하여 불러오기할수있다.

1)예에서 씬에 cube 오브젝트를 생성하였다.

 

2)cube 오브젝트의 프리팹을 생성하였다.

 

3)일반적으로 스크립트에서 게임오브젝트 타입의 변수를 선언하고 에디터에서 직접 참조시켜서 해당 오브젝트를 복제 및 생성할수있다.

 

4)게임을 시작하면 씬에 프리팹 게임오브젝트를 복제 및 생성한다.

 

Resources.Load 함수를 사용한 방법

5)프로젝트의 Assets 폴더 하위에 Resources 폴더를 생성한다. 

 

6)Resources 폴더 하위에 런타임에 불러올 에셋들을 위치시킨다. 예에서 Resources 폴더의 하위에 추가적인 Prefabs 폴더를 생성하고 여기에 프리팹 에셋을 위치시켰다.

 

7)스크립트에서 리소스 폴더의 에셋을 불러오기할때 아래와 같이 함수를 호출한다. 예에서 GameObject 유형의 에셋을 해당 위치에서 불러오기한다.

 

8)동일한 방법으로 다양한 유형의 에셋들을 불러오기할수있다(GameObject, TextAsset, Texture2D, Sprite, AudioClip, etc)

 

Resources 폴더

https://docs.unity3d.com/ScriptReference/Resources.html

 

Resource.Load 함수

https://docs.unity3d.com/ScriptReference/Resources.Load.html

 

 

반응형
반응형

출처: https://bluemeta.tistory.com/3

1. Time.timeScale이란?

 원래 스케일(Scale)이란 단어의 뜻이 규모, 등급 등을 나타내듯이, 유니티에서 Time.timeScale 프로퍼티는 시간이 어떤 속도로 흘러가는지를 의미합니다. Time.timeScale의 값이 1.0f라면 현재 유니티 씬의 시간이 실제 시간(real time)으로 흐른다는 것을 의미합니다.

 반면에 0.5f라면 시간이 흐르는 속도가 절반이 된다는 의미입니다.

 만약 0.0f라면 모든 게임오브젝트가 정지합니다. 즉, 정지/포즈(pause) 상태를 구현할 수 있습니다.

 당연히 2.0f라면 2배의 속도로 움직이겠죠.

 다만 Time.timeScale 프로퍼티는 정적 프로퍼티(static property)이기 때문에 모든 씬의 게임오브젝트들이 공유하고 있습니다. 그러므로 Time.timeScale의 값을 변경하면 씬의 모든 게임오브젝트가 영향을 받습니다.

 아래 코드를 확인해보겠습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        if (Input.GetButtonDown("Fire1")) {
            if (Time.timeScale == 1.0F)
                Time.timeScale = 0.7F;
            else
                Time.timeScale = 1.0F;
            Time.fixedDeltaTime = 0.02F * Time.timeScale;
        }
    }
}
cs

 

 위 코드를 보면 "Fire1" 키를 누르고 있는 동안은 Time.timeScale이 0.7f로 바뀌는 것을 알 수 있습니다. 즉 키를 누르고 있는 동안 시간이 0.7배의 속도로 흐르게 되는 것이죠.

 그런데 조금 더 자세히 보니까 Time.fixedDeltaTime도 바꾸는 코드가 있네요?

 

2. Time.fixedDeltaTime도 함께 바꾸기

 그리고 또 하나 중요한 것! 유니티 문서에 따르면 Time.timeScale을 바꾸었을 때는 Time.fixedDeltaTime도 수정하길 권장하고 있습니다.

 위 코드의 11번째 줄을 보면 Time.fixedDeltaTime = 0.02f * Time.timeScale이라는 코드를 볼 수 있는데요. 여기서 0.02f는 유니티 엔진이 물리 연산을 담당하는 FixedUpdate() 메소드를 초당 50회(1초/50회 = 0.02f) 호출하기 때문입니다. 그리고 유니티에서 물리 연산을 담당하는 타이머는 별도의 타이머로 동작하기 때문에 Time.timeScale에 변화를 주었다면 Time.fixedDeltaTime도 수정하는 것입니다.

 

3. 만약 특정 게임오브젝트의 타임스케일을 바꾸고 싶다면?

 딱히 이를 위한 프로퍼티가 있는 것은 아닙니다. 스크립트를 통해서 구현해야만 합니다. 다만 아래의 방법을 생각해볼 수 있을 것 같습니다.

  1. 메카님(Mecanim) 애니메이션 : Animator.speed라는 프로퍼티가 있습니다. 이 값을 조절할 수 있습니다.
  2. 리지드바디(Rigidbody) 유니티 물리 엔진 : 힘을 가해주는(속도를 변화시키는) Rigidbody.AddForce(), 토크를 가해주는(각속도를 변화시키는 Rigidbody.AddTorque() 메소드 등의 패러미터 값을 조절해주어야 합니다.
  3. 트랜스폼(Transform) : 마찬가지로 Transform.Translate(), Transform.Rotate() 메소드 등의 패러미터 값을 조절해주어야 합니다.

 

디아블로3의 위저드 스킬인 감속 지대를 구현하려면? 

 

4. 정리

  1. Time.timeScale 프로퍼티는 모든 게임오브젝트의 시간 어떤 속도로 흘러가는지를 나타낸다. 기본값은 1.0f이다.
  2. Time.timeScale 프로퍼티를 바꾸었다면 Time.fixedDeltaTime 역시 바꾸는 것이 좋다. (Time.fixedDeltaTime = 0.02f * Time.timeScale)
  3. 예를 들어 Time.timeScale 프로퍼티가 0.0f이면 정지/포즈 상태를, 2.0f이면 2배로 시간이 빨리 흘러가는 것을 구현할 수 있다.
  4. 특정 게임오브젝트의 타임스케일을 바꾸기 위해서는 각 컴포넌트(Animator, Rigidbody, Transform 등)에 맞는 방법을 사용해야 한다.
반응형

+ Recent posts