본문 바로가기
Programing/unity

유니티,unity,반대로 날아오는 오브젝트,Vector3.back,LookRotation,Instantiate

by 고니피즈 2017. 2. 23.
반응형

public class ballMove : MonoBehaviour {


public float speed;

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

transform.position += Vector3.back * Time.deltaTime * speed;

// Vector3.back 반대방향으로 오게 함

}

}




public class ballCopy : MonoBehaviour {


public GameObject ball;


Vector3 pos;


// Use this for initialization

void Start () {

StartCoroutine(Sleep());

}


IEnumerator  Sleep()

{  

while (true) {

int randx= Random.Range(-10, 10);

int randy= Random.Range(2, 10);

pos = new Vector3 (randx,randy,30);

Instantiate (ball,pos, Quaternion.LookRotation(Vector3.back));

                                 //복제코드 

//Quaternion.LookRotation(Vector3.back) 반대방향으로 바라보게 함

yield return new WaitForSeconds (2.0f);

// 2초간 딜레이로 복제 


}

}

   

}


반응형