IEnumerator findTarget() { yield return(new WaitForSeconds(aiWaitTime)); if (m_gameOver == false) { findBallAndPocket(); findClosestAngleToBall(); if (m_targetBall) { //we got a foul ball, lets try putting the ball in line with the line. getNomBallsInWay(); if (foul) { //findGoodFoulSpot(); m_power = 30; } //always shoot 100% on the first shot! if (m_firstShot == false) { m_power = 100; m_firstShot = true; } Vector3 targetPos = m_targetPos; targetPos.y = m_whiteBall.transform.position.y; m_cue.setTarget(m_targetBall, targetPos); m_cue.setPower(m_power); m_whiteBall.setTarget(m_targetBall, targetPos); m_whiteBall.transform.LookAt(m_targetBall.transform.position); yield return(new WaitForSeconds(1f)); m_cue.fireBall(); m_canFire = true; } else { Debug.Log("FIND NEW TARGET" + Time.time); StartCoroutine(findTarget()); } } }
public void fireBallRPC() { m_requestFire = false; if (GetComponent <AudioSource>()) { GetComponent <AudioSource>().PlayOneShot(onHitCueAC, 1f); } //lets set the balls target and the target position. When the white ball hits the first ball we will set the ball to point at the target. m_whiteBall.setTarget(m_targetBall, m_targetPos); Debug.Log("FIRE BALL" + m_whiteBall.name); m_whiteBall.fireBall(m_whiteBall.transform.forward * m_powerScalar * power); m_state = State.ROLL; poolCueGO.SetActive(false); transform.parent = null; }