コード例 #1
0
 IEnumerator CorCreateBullet()
 {
     while (bullets.Count < maxBullet)
     {
         OctopusBullet temp = Instantiate(bulletPrefab, transform.position, Quaternion.identity, transform.parent);
         temp.gameObject.SetActive(false);
         bullets.Add(temp);
         yield return(null);
     }
 }
コード例 #2
0
    IEnumerator CorMoveOctopus()
    {
        float fixedDeltatime = Time.fixedDeltaTime;

        while (true)
        {
            //if (Mathf.Abs(Vector3.Distance(transform.localPosition, myStartPos)) > distance)
            //{
            //    gameObject.SetActive(false);
            //    yield break;
            //}
            if (transform.localPosition.y >= distance)
            {
                gameObject.SetActive(false);
                yield break;
            }

            switch (state)
            {
            case State.Up:
                rigid2D.velocity = Vector3.zero;
                transform.Translate(direction * fixedDeltatime * moveSpeed * 1.2f, Space.World);
                break;

            case State.Down:
                transform.Translate(Vector3.down * fixedDeltatime * moveSpeed * 0.8f, Space.World);
                break;

            case State.Fire:
                OctopusBullet octopus = null;
                for (int i = 0; i < octopusBullets.Count; i++)
                {
                    octopus = octopusBullets[i];
                    if (octopus.gameObject.activeSelf == false)
                    {
                        octopus.transform.position = transform.position;
                        octopus.gameObject.SetActive(true);
                        octopus.InitBullet(bulletSpeed, bulletReach, Vector3.left);
                    }
                }
                rigid2D.AddForce(Vector3.right * 0.03f, ForceMode2D.Impulse);
                break;

            case State.Idle:
                transform.Translate(Vector3.down * fixedDeltatime * moveSpeed * 0.1f, Space.World);
                break;

            default:
                break;
            }
            yield return(new WaitForFixedUpdate());
        }
    }
コード例 #3
0
    private void MoveStop()
    {
        moving    = true;
        moveSpeed = 0;
        OctopusBullet bullet = null;

        for (int i = 0; i < bullets.Count; i++)
        {
            bullet = bullets[i];
            if (bullet.gameObject.activeSelf == false)
            {
                bullet.transform.position = transform.position;
                bullet.gameObject.SetActive(true);
                bullet.InitBullet(bulletSpeed, distance,
                                  Quaternion.Euler(0, 0, Random.Range(-45, 46)) * Vector3.down);
                Invoke("SetMove", 1.0f);
                return;
            }
        }
        Invoke("SetMove", 1.0f);
    }