Exemplo n.º 1
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     for (int i = 0; i < m_asteroidsSpawnOnDestroy; ++i)
     {
         GameObject go = m_astroidTypeOnDestroy?.Request();
         go.transform.position = transform.position;
         Quaternion randomRotation = Quaternion.identity;
         randomRotation.eulerAngles = new Vector3(0f, 0f, Random.Range(0f, 360f));
         go.transform.rotation      = randomRotation;
     }
     AsteroidManager.m_instance.NotifyDestruction();
     Destroy(gameObject);
 }
Exemplo n.º 2
0
 private void SetupLevel()
 {
     for (uint i = 0; i < m_initCount; ++i)
     {
         Camera     camera            = Camera.main;
         GameObject go                = m_asteroidType.Request();
         Vector2    randomScreenPoint = new Vector2(Random.Range(0f, camera.pixelWidth),
                                                    Random.Range(0f, camera.pixelHeight));
         Vector3 randomPoint = camera.ScreenToWorldPoint(randomScreenPoint);
         randomPoint.z = 0f;
         Vector3 safeDistanceVector = randomPoint - m_ship.position;
         if (safeDistanceVector.magnitude < m_safeDistance)
         {
             safeDistanceVector = safeDistanceVector.normalized;
             randomPoint        = m_ship.position + safeDistanceVector * m_safeDistance;
         }
         Quaternion randomRotation = Quaternion.identity;
         randomRotation.eulerAngles = new Vector3(0f, 0f, Random.Range(0f, 360f));
         go.transform.position      = randomPoint;
         go.transform.rotation      = randomRotation;
     }
 }