Helo guys I would like to know what is wrong with this script. When I’m accessing the IEnum on the other script 1 it’s not working though it didn’t have an error.
Script 1
Rigidbody rbBall;
public Vector3 ballPosition;
float ballSpeed = 50f;
private void Start()
{
rbBall = GetComponent();
transform.position = ballPosition;
StartCoroutine(BallStart());
}
public IEnumerator BallStart()
{
yield return new WaitForSeconds(5);
rbBall.constraints = RigidbodyConstraints.FreezePositionY;
float xBallPath = 1/*Random.Range(-2, 2)*/;
rbBall.velocity = new Vector3(xBallPath * ballSpeed, 0, 0 );
}
Script 2
public int scorePlayer2;
GameObject ball;
Ball ballScript;
private void Start()
{
ball = GameObject.Find(“Ball”);
ballScript = ball.GetComponent();
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "Ball")
{
Debug.Log("Hit");
scorePlayer2++;
collision.rigidbody.velocity = Vector3.zero;
StartCoroutine(ballScript.BallStart());
}
}