random rotation problem

Hi there guys

I need to rotate my “ball” game object in a to a random amount before the force is added. Can someone tell me why this is not working?

if(gameState == "power")
	{
	
		if(barDisplay < 1.8)
			{
				barDisplay += Time.deltaTime * 0.7;
			}
			else
			{
				curHoleShots +=1;
				GameObject.FindWithTag("ball").GetComponent("Score").totalShots +=1;
				lastShotPosition = ball.transform.position;
				ball.transform.rotation.y += Random.Range(1,100);
				ball.rigidbody.AddForce(transform.forward * 25);
				gameState = "aim";
				barDisplay = 0;
			}
	}

transform.rotation is a quaternion; changing the x/y/z values doesn’t do what you’re thinking. Use transform.Rotate(Vector3.up * Random.Range(1, 100)).

–Eric

Thanks eric, that worked.

Just one more thing, it seems like the rotation only takes place after the AddForce is applied. I hit a shot and only after that the rotation is applied???

Any ideas?

Thanks, I got it sorted with this line:

ball.rigidbody.AddForce(Vector3(Random.Range(50,200),0,Random.Range(-100,100)));