2015-02-01 3 views
0

전방으로 이동하여 매초마다 프리 프레임을 생성하는 gameobject가 있습니다. 유일한 문제는 산란이 고르지 않은 것처럼 보이고 때로는 물체가 멀리 떨어져 있고 때로는 겹쳐지는 경우도 있습니다. 나는 spawntime과 거리를 변경함으로써 이것을 해결할 수 있지만, ios에서 테스트했을 때 다시 깨졌습니다.프리폼을 움직이고 생성하는 GameObject

다른 객체에서 게임 객체를 밀어내는 스크립트를 만들려고했으나 객체를 밀어내어 다른 객체와 다른 객체에 쳤습니다.

내가 할 수 있기를 원하는 것은 spawner가 앞으로 나아가고 prefab이 겹치지 않도록 prefab을 내려 놓는 것입니다. 나는 이걸로 일할 필요가있어. 여기

using UnityEngine; 
using System.Collections; 

public class SpawnScript : MonoBehaviour { 

    public GameObject[] obj; 
    //public float spawnMin = 1; 
    //public float spawnMax = 1; 
    //public float spawnDistance = 0.1f; 
    //private float barDisplay = 3; 
    public float timeLeft = 0.1f; 
    static bool finishTimer = false; //i made this global so you can access from other scripts 
    static bool timerStarted = false; 

    //private GameObject GroundSpawner; 

    // Use this for initialization 
    void Start() { 
     timerStarted = true; 

    } 

    void Update(){ 
     Timer(); 

     transform.Translate(Vector3.forward * 0.1f); 


    } 

    void Timer(){ 

     if (timerStarted == true) {   
      timeLeft -= Time.deltaTime;   
      if (timeLeft <= 0.0f) {   
       Spawn(); 
       timerStarted = false; 
      } 
     } 
    } 

    void Spawn(){ 
     //GroundSpawner = GameObject.Find ("Ground Spawner"); 

     //if (GroundSpawner.transform.position) { 
        //Invoke ("Spawn", Random.Range (spawnMin, spawnMax)); 
        Invoke ("Spawn", 1.75f); 

        Instantiate (obj [Random.Range (0, obj.Length)], transform.position, Quaternion.identity); 

     // } 
    } 
} 

이 땅이 다른 게임 오브젝트 스크립트에서 추진하고 : 인스턴스화 팹 사이

using UnityEngine; 
using System.Collections; 

public class GroundHittingSelf : MonoBehaviour { 

    // Use this for initialization 
    void Start() { 

    } 

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

    } 

    void OnCollisionEnter(Collision other) { 
     Debug.Log("Hitting Ground without tag"); 
     if (other.gameObject.tag == "Ground") { 
      //transform.position += new Vector3(0, 0, 0.1f); 
      Debug.Log("Hitting Ground with tag"); 

     } 
    } 
} 
+0

음, 정확히 무엇을 하려는지 이해할 수 없으므로 3.0f가됩니다. 귀하의 질문에 이미지 (스크린 샷)를 게시 할 수 있습니까? –

답변

1

요철 공간 내가 여기

에 스폰 스크립트입니다 때문에이 깨진 것 같아요 SpawnScript의 gameObject가 속도가 변함에 따라 움직이고 있다는 사실로부터옵니다.

deltatime을 고려하지 않고 transform.Translate의 위치를 ​​Update 범위 내에서 변경하기 때문입니다. Update은 코드를 실행중인 시스템에서 호출 할 수 있기 때문에 초 단위로 여러 번 호출됩니다. 예를 들어 기계가 배경 작업을 수행하고 있다면, Update은 덜 자주 호출됩니다. 이 경우 gameObject 속도가 느려집니다. 또는 더 나쁜 경우, 동일한 코드가 다른 시스템에서 실행되면 훨씬 더 빠르거나 느려질 것입니다.

은 계정에 deltatime을 고려하여 고정 할 수 있습니다

transform.Translate(Vector3.forward * Time.deltaTime * 3.0f); 

Deltatime는 일반적으로 일정한 요구를 다시 설정할 수 있도록 아주 작은 숫자입니다. 예를 들어, 30fps로 좋은 속도를 얻은 경우 3.0f * (1.0f/30.0f) = 0.1f

관련 문제