public Bolt2 GetFromPool() { for (int i = 0; i < boltList.Count; i++) { if (!boltList[i].gameObject.activeInHierarchy) { return(boltList[i]); } } Bolt2 temp = Instantiate(bolt); boltList.Add(temp); return(temp); }
private IEnumerator AutoShoot() { int degree = 0; int speed = 10; WaitForSeconds s1 = new WaitForSeconds(1.5f); while (true) { yield return(s1); if (attackStart) { degree = 0; bolt = BoltP.GetFromPool(); bolt.transform.position = boltPos.position; bolt.gameObject.SetActive(true); bolt.GetComponent <Rigidbody>().velocity = new Vector3(Mathf.Sin(Mathf.PI / 180 * degree), 0, -Mathf.Cos(Mathf.PI / 180 * degree)) * speed; bolt.GetComponent <Rigidbody>().rotation = Quaternion.Euler(90, -degree, 0); degree = 13; bolt = BoltP.GetFromPool(); bolt.transform.position = boltPos.position + new Vector3(0.3f, 0, 0); bolt.gameObject.SetActive(true); bolt.GetComponent <Rigidbody>().velocity = new Vector3(Mathf.Sin(Mathf.PI / 180 * degree), 0, -Mathf.Cos(Mathf.PI / 180 * degree)) * speed; bolt.GetComponent <Rigidbody>().rotation = Quaternion.Euler(90, -degree, 0); degree = -13; bolt = BoltP.GetFromPool(); bolt.transform.position = boltPos.position + new Vector3(-0.3f, 0, 0); bolt.gameObject.SetActive(true); bolt.GetComponent <Rigidbody>().velocity = new Vector3(Mathf.Sin(Mathf.PI / 180 * degree), 0, -Mathf.Cos(Mathf.PI / 180 * degree)) * speed; bolt.GetComponent <Rigidbody>().rotation = Quaternion.Euler(90, -degree, 0); sc.PlayEffectSound(eSoundEffect.wea_enemy); } } }