// Update is called once per frame void Update() { transform.position = firstPos; timeCount += Time.deltaTime; if (timeCount > coolTime) { playTime += Time.deltaTime; anim.SetBool("isThrow", true); animationTime = anim.GetCurrentAnimatorStateInfo(0).length; if (playTime >= animationTime) { var camera = GameObject.Find("Main Camera"); var distance = Mathf.Abs(Vector3.Distance(camera.transform.position, transform.position)); if (distance < soundHearableDistance) { audioSource.Play(); } for (int i = 0; i < throwNum; ++i) { GameObject obj = Instantiate(beanBullet, transform.position, Quaternion.identity); BeanBullet script = obj.GetComponent <BeanBullet>(); script.firstSpeed = new Vector2(throwPower * Mathf.Cos(Mathf.PI / 4 + Mathf.PI / (2 * (throwNum - 1)) * i), throwPower * Mathf.Sin(Mathf.PI / 4 + Mathf.PI / (2 * (throwNum - 1)) * i)); } anim.SetBool("isThrow", false); timeCount = 0; playTime = 0; } } }
// Update is called once per frame void Update() { script.FollowingMove(); playTime += Time.deltaTime; if (playTime >= throwTiming * animationTime) { var camera = GameObject.Find("Main Camera"); var distance = Mathf.Abs(Vector3.Distance(camera.transform.position, transform.position)); if (distance < soundHearableDistance) { audioSource.PlayOneShot(beanBulletSound); } for (int i = 0; i < throwNum; ++i) { GameObject obj = Instantiate(beanBullet, transform.position, Quaternion.identity); BeanBullet script = obj.GetComponent <BeanBullet>(); script.firstSpeed = new Vector2(throwPower * Mathf.Cos(Mathf.PI / 4 + Mathf.PI / (2 * (throwNum - 1)) * i), throwPower * Mathf.Sin(Mathf.PI / 4 + Mathf.PI / (2 * (throwNum - 1)) * i)); } playTime = 0; } }